[Tutor] guess-my-number programme
ADRIAN KELLY
kellyadrian at hotmail.com
Fri Sep 23 21:25:12 CEST 2011
import random
print("\tWelcome to 'Guess My Number'!")
print("I'm thinking of a number between 1 and 100.")
print("Try to guess it in as few attempts as possible.\n")
# 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 = tries + 1
print("You guessed it! The number was", the_number)
print("And it only took you", tries, "tries!\n")
input("\n\nPress the enter key to exit.")
*******************************************************************
can anyone explain the tries part of this programme to me i know its meant to count the number of guesses made by the user by adding 1 but i just cant figure out how it does this..........can someone explain?? i.e. tries = 1, tries +1 etc.... cant get my head around it...
thanks all
Adrian Kelly
1 Bramble Close
Baylough
Athlone
County Westmeath
0879495663
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110923/ab34a3e7/attachment.html>
More information about the Tutor
mailing list