[Tutor] Help with Guess the number script

Alan Gauld alan.gauld at btinternet.com
Sat Mar 8 10:13:09 CET 2014


On 08/03/14 01:23, Scott W Dunning wrote:
>
> On Mar 7, 2014, at 11:02 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> GOT IT!!  Finally!  Thanks for all of your help!!
>
> This is what I got, not sure if it’s correct but it’s working!

Well done.
And now that you have the right set of tests you can
half the number of lines by combining your if
conditions again, like you had in the original
post. ie. Bring your hot/cold/warm tests together.


> def print_hints(secret, guess):
>      if guess < 1 or guess > 100:
>          print
>          print "Out of range!"
>          print
>      if guess < secret:
>          print
>          print "Too low!"
>          if guess < secret - 10:
>              print "You are cold!"
>              print
>              print "Please play again!"
>          elif guess < secret - 5:
>              print "You are warmer!"
>              print
>              print "Please play again"
>          else:
>              print "You're on fire!!"
>              print
>              print "Please play again"
>      if guess > secret:
>          print
>          print "Too high!"
>          if guess > secret + 10:
>              print "You are cold!"
>              print
>              print "Please play again!"
>          elif guess > secret + 5:
>              print "You are warmer!"
>              print
>              print "Please play again"
>          else:
>              print "You're on fire!!"
>              print
>              print "Please play again"
>

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list