This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: syntax error at "while" statement in IDLE/python shell
Type: behavior Stage:
Components: IDLE Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, victorywin
Priority: normal Keywords:

Created on 2011-03-07 16:54 by victorywin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg130261 - (view) Author: Victor (victorywin) Date: 2011-03-07 16:54
Hi and please help me understand if it is a bug, or..,as someone said, there's a 'bug' in my understanding:
(Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32) (windows vista, the regular windows python installer)
It's about the following code:

while True:
    s = input('Enter something : ')
    if s == 'quit':
        break
    print('Length of the string is', len(s))
print('Done')

when I put it in the IDLE's editor, and run it from there ("Run module F5"), it runs fine; but when I try to type it in the python shell (IDLE), or in the python command line, it gives errors, though I tried to edit it differently:

>>> while True:
        s = input('Enter something : ')
        if s == 'quit':
            break
        print('Length of the string is', len(s))
print('Done')
SyntaxError: invalid syntax
>>> while True:
        s = input('Enter something : ')
        if s == 'quit':
            break
        print('Length of the string is', len(s))
    print('Done')
SyntaxError: unindent does not match any outer indentation level
>>>

The only way I noticed it would accept is to set the last "print" statement directly under/in the block of "while": which is not the intention. (According to the docs, while statement should work without the "else" option). Is this a bug?
Thanks, Victor
p.s. the example is taken from http://swaroopch.com/notes/Python_en:Control_Flow
msg130263 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-03-07 17:05
No this is not a bug. You're trying to execute two statements in one go in IDLE, which it doesn't support. You need to run your while loop as a single statement, then your print('Done').
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55642
2011-03-08 14:42:10SilentGhostsetstatus: pending -> closed
2011-03-07 17:05:44SilentGhostsetstatus: open -> pending

nosy: + SilentGhost
messages: + msg130263

resolution: not a bug
2011-03-07 16:54:43victorywincreate