-2

As You see at the 2 pics the iteration loop works well with canopy but with IDLE Python 2.7.10 says: Syntax error

Why?

Orest Hera
  • 6,706
  • 2
  • 21
  • 35

1 Answers1

3

It looks to me like IDLE was confused by how you entered multiple statements. You need to enter a blank line after the indented suite of the while loop so it knows the statement is over (and that there's not an else block attached). You'll know you've finished the statement when the >>> prompt appears again.

>>> while ...
        # stuff here
        # more stuff
        # leave a blank line afterwards!

>>> print ('Goodbye!')

Your code would work just fine in IDLE if you put it into a module and ran the module. It's only the interactive console that has issues.

Blckknght
  • 100,903
  • 11
  • 120
  • 169
  • Thanks so much can You tell me how to make a blank line I'm just a beginner :) – Mohammed Hany Oct 28 '15 at 20:32
  • That depends on how you're entering the code. If you're typing it by hand, just press Enter twice after the last line of the loop. If you're copying and pasting from a source that has the code tightly packed together, that's tougher. You'll need to copy the statements separately, pressing Enter in between manually. – Blckknght Oct 28 '15 at 21:47
  • but then the IDLE will excute the loop before without the statement (print) I think adding else : print ('Goodbye!') would be better or do You have another way ?! – Mohammed Hany Oct 29 '15 at 06:32
  • An else statement could work, though usually you only attach one to a loop where you might or might not be `break`ing out, rather than having the condition become falsey at some point. I think the real question though is why you want the to have both the loop and the print at the end happen at the same time? They're separate statements, so you should run one then run the next one. – Blckknght Oct 29 '15 at 08:54