1

I am using IDLE and Python 2.7. I am new to python and programming in general so sorry if this is extremely newbish, which it probably is.

Anyway, I'm following along and taking notes with python video and I was using IDLE and I keep getting this syntax error https://i.sstatic.net/DHcyP.png . I tried moving "else:" back to see if that was the problem but that didn't help. Just giving me a hint would help lol, thanks.

6
  • 4
    else: must line up exactly under the if. Commented May 27, 2014 at 2:37
  • I have tried that i.imgur.com/mXgBzrl.png Commented May 27, 2014 at 3:36
  • 1
    I see you're trying to enter that into an interactive Python shell. Normally the interactive shell is only convenient for entering and trying single-line statements, rather than writing whole programs. I recommend you step forward to where you are actually writing code in an editor, saving it in a file, and running the code using the normal Python runtime environment. Commented May 27, 2014 at 3:40
  • Well the vid I was watching was doing this just fine in the interactive shell so I was confused as why this wasn't working for me, I'll try it in an actual file and see if it work. Commented May 27, 2014 at 3:53
  • 1
    And wow, it works fine as an actual file but not in the Interactive Shell >.> FFS.. Thanks Greg lol. Commented May 27, 2014 at 3:59

2 Answers 2

1

White space is significant in loops and if-else in python, I believe you wanted something like

if sister_age > brother_age:
  print("Sister is older")
else:
  print("Brother is older")
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah that's what I want and I've entered it like that but it keeps giving me an error. Again see i.imgur.com/mXgBzrl.png I've tried various ways of indenting >.>
0

I solve your problem and solution is very simple...you just have to start the else part from the start of IDLE like i have done you will get your desirable output . Output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.