Persistent failure of 'break' statement ( novice )

pdlemper at earthlink.net pdlemper at earthlink.net
Sat Jun 13 22:27:51 EDT 2009


On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin
<sjmachin at lexicon.net> wrote:

>On Jun 14, 10:20 am, pdlem... at earthlink.net wrote:
>
>> Now no error message, but it will go on forever despite repeatedly
>> entering 0.  Have to get out with ctrl-c .    
>
>>            Frusting: I'm missing something fundamental. Dave WB3DWE
>
>After you hit the zero key, do you hit the Enter key?
>
>If the answer is yes, then our crystal balls have proved useless.
>You'll have to supply some meaningful detail. If you are pasting your
>script into a Python interactive prompt, stop doing that, save your
>script as a file, and run it from the command line.
>
>Here's a script for you to use. It has some diagnostic print() calls
>in it so that we can see what is going wrong.
>
>8<----- cut here
>import sys
>print(sys.version)
>assert sys.version.startswith('3.')
>while True :
>    text = input('Enter a number -> ')
>    print('You entered', ascii(text))
>    if text != "0":
>        print('That is NOT the digit zero!')
>    num = int(text)
>    print('Value:', num)
>    if num == 0:
>        break
>print('done')
>8<----- cut here
>
>And when you run it, copy the outout and paste it into your return
>message/posting, like I've done below:
>
>[I called my copy break_fail.py]
>
>C:\junk>\python30\python break_fail.py
>3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)]
>Enter a number -> 9
>You entered '9'
>That is NOT the digit zero!
>Value: 9
>Enter a number -> 0
>You entered '0'
>Value: 0
>done
>
>C:\junk>
>
>Hoping this helps,
>John


John : Hitting Enter solved it.  Thanks so much.  I was treating
input() as getch() or getche() .               Dave WB3DWE



More information about the Python-list mailing list