Nested structures question
Jason Staudenmayer
jasons at adventureaquarium.com
Wed Jan 12 15:04:36 EST 2011
Return False instead of break should work
else:
print "You guessed it! The number was", the_number
print "And it only took you", tries, "tries!\n"
return False
Jason
..·><((((º>
> -----Original Message-----
> From:
> python-list-bounces+jasons=adventureaquarium.com at python.org
> [mailto:python-list-bounces+jasons=adventureaquarium.com at pytho
> n.org] On Behalf Of Physics Python
> Sent: Wednesday, January 12, 2011 2:53 PM
> To: python-list at python.org
> Subject: Re: Nested structures question
>
>
> Thanks,
>
> Is this an indentation problem then?
> How do I update the sentinel within the secondary while loop.
> I am trying to avoid using breaks by the way, as I can
> program this example using breaks:
>
> --- start---
> import random
> print "\tWelcome to 'Guess my number'!:"
> print "\nI'm thinking of a number between 1 and 100."
> print "Try to guess it in as few attempts as possible.\n"
>
> the_number = random.randrange(1,101)
>
> tries = 0
>
> while True:
> guess = int(raw_input("Take a guess: "))
> tries += 1
> if guess > the_number:
> print "Lower..."
> elif guess < the_number:
> print "Higher..."
> else:
> print "You guessed it! The number was", the_number
> print "And it only took you", tries, "tries!\n"
> break
> if tries == 7:
> print "Wow you suck! It should only take at most 7 tries!"
> break
>
> raw_input ("\n\nPress the enter key to exit.")
>
> --- end ---
>
> But the book states that this can be done without needing to
> use breaks.
>
> Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list