[Tutor] Help with looping...
A. R. Goldman
argoldman@mindspring.com
Fri, 31 Mar 2000 18:18:38 -0500
--------------5FB52E9E112C10EF21F1C327
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Greetings...
I have been working on a simple number guessing game... and I
would like to add the ability to keep playing games repeatedly. I
suspect that this is done with the 'continue' command... but I am
either wrong in that assumption... or can't get the syntax... I'm
including my code as it stands... any help would be gratefully
appreciated...
Many Thanks
Rick Goldman
and here's the script:
> lower = 1
> upper = 200
> while 1:
> print "lower", lower, "upper", upper
> if lower > upper:
> print "cheetas never prosper"
> break
> guess = (lower + upper) /2
> print "Is it", guess, "?"
> outcome = raw_input("Is the number higher, lower, or equal to my guess?")
> if outcome == "lower":
> upper = guess -1
> elif outcome == "higher":
> lower = guess + 1
> elif outcome == "equal":
> answer = raw_input("That was fun. Another?" )# I assume that I need something here... but what?
> if answer == "no":
> print "Thank you"
> break
> else:
> print "lower, higher or yes, you Hoser"
>
>
--------------5FB52E9E112C10EF21F1C327
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Greetings...
<br>I have been working on a simple number guessing game... and I would
like to add the ability to keep playing games repeatedly. I suspect that
this is done with the 'continue' command... but I am either wrong in that
assumption... or can't get the syntax... I'm including my code as it stands...
any help would be gratefully appreciated...
<br>Many Thanks
<br>Rick Goldman
<p>and here's the script:
<blockquote TYPE=CITE>
<pre>lower = 1
upper = 200
while 1:
print "lower", lower, "upper", upper
if lower > upper:
print "cheetas never prosper"
break
guess = (lower + upper) /2
print "Is it", guess, "?"
outcome = raw_input("Is the number higher, lower, or equal to my guess?")
if outcome == "lower":
upper = guess -1
elif outcome == "higher":
lower = guess + 1
elif outcome == "equal":
answer = raw_input("That was fun. Another?" )# I assume that I need something here... but what?
if answer == "no":
print "Thank you"
break
else:
print "lower, higher or yes, you Hoser"
</pre>
</blockquote>
</html>
--------------5FB52E9E112C10EF21F1C327--