[Tutor] Print/Loop Question
michael scott
jigenbakuda at yahoo.com
Thu Mar 17 20:02:13 CET 2011
Hi Jeff how are you today?
Well about your question... I copy and pasted your code and it worked fine for
me. Well except for in the code bit you posted you forgot to give a guess a
value before it was referred to. So under number = 44 I just wrote guess = 0 and
it worked fine.
But perhaps I'm misunderstanding your question, because I did not get any of the
errors you mentioned.
Here is what I got
jigenbakuda at jigenbakuda-HP-G50-Notebook-PC:~$ python 6.py
Guess a number between 1 - 100: 45
Too high
Guess a number between 1 - 100: 43
Too low
Guess a number between 1 - 100: 44
Just right
jigenbakuda at jigenbakuda-HP-G50-Notebook-PC:~$
with this code
number = 44
guess = 0
while guess != number :
guess = int(raw_input("Guess a number between 1 - 100: "))
if guess > number :
print ("Too high")
elif guess < number :
print ("Too low")
else:
print ("Just right" )
If I'm misunderstanding your problem, I'm sorry.
----
What is it about you... that intrigues me so?
________________________________
From: Jeff Goodwin <jeffbgoodwin at gmail.com>
To: tutor at python.org
Sent: Thu, March 17, 2011 2:19:17 PM
Subject: [Tutor] Print/Loop Question
I'm trying to run the below program and get it to print out feedback as the loop
goes. However, if you enter a number too high or too low, it skips the print
statement under the if and elif clauses and asks the user to "Guess a
number between 1-100" again. Any suggestions on how to get it to print the "too
high" and "too low" responses?? Once the number is entered correctly it prints
"Just Right" and exits correctly.
number = 44
while guess != number :
guess = int(raw_input("Guess a number between 1 - 100: "))
if guess > number :
print ("Too high")
elif guess < number :
print ("Too low")
else:
print ("Just right" )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110317/b3dd07c9/attachment-0001.html>
More information about the Tutor
mailing list