On 13/10/14 11:40, אופיר לירון wrote:

# set the initial values

the_number = random.randint(1, 100)
guess = int(input("Take a guess: "))
tries = 1

# guessing loop
while guess != the_number:
     if guess > the_number:
         print("Lower...")
     else:
         print("Higher...")
     guess = int(input("Take a guess: "))

     tries += 1
     if tries > 5:
         break

so far so good....
almost...

     if guess != the_number:
         print ("you failed, the number was", the_number)

This is still inside the loop. You want to remove the
indentation so this only happens after you exit the loop.
Otherwise you tell the user the answer before they guess
it (or have 5 goes) and it doesn't work right if the
first guess is correct...

input("\n\nPress the enter key to exit.")

You need the if/else to look like this.

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

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to