Re: Persistent failure of 'break' statement ( novice )
- From: pdlemper@xxxxxxxxxxxxx
- Date: Sat, 13 Jun 2009 21:27:51 -0500
On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin
<sjmachin@xxxxxxxxxxx> wrote:
On Jun 14, 10:20 am, pdlem...@xxxxxxxxxxxxx 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
.
- Follow-Ups:
- Re: Persistent failure of 'break' statement ( novice )
- From: John Machin
- Re: Persistent failure of 'break' statement ( novice )
- References:
- frustrating failure of 'break' statement ( novice )
- From: pdlemper
- Persistent failure of 'break' statement ( novice )
- From: pdlemper
- Re: Persistent failure of 'break' statement ( novice )
- From: John Machin
- frustrating failure of 'break' statement ( novice )
- Prev by Date: Re: Good books in computer science?
- Next by Date: Re: Good books in computer science?
- Previous by thread: Re: Persistent failure of 'break' statement ( novice )
- Next by thread: Re: Persistent failure of 'break' statement ( novice )
- Index(es):
Relevant Pages
|