Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 under 10 attempts.\n"
- # set the initial values
- the_number = random.randrange(100) + 1
- # Fixed crash on non numbers
- guess = raw_input("take a guess: ")
- if (!guess.isdigit())
- print "Please enter a valid number"
- else:
- guess = int(guess)
- tries = 1
- triesleft = 9
- while (guess != the_number):
- if (guess > the_number):
- print "Lower..."
- print "You have", triesleft, "guesses left!"
- else:
- print "Higher..."
- print "You have", triesleft, "guesses left!"
- guess = int(raw_input("Take a guess: "))
- tries += 1
- triesleft += -1
- if (triesleft == 0):
- print "You have lost."
- print "You have no more guesses left."
- raw_input("\n\nPress the enter key to exit.")
- exit()
- print "You guessed it! The number was", the_number
- print "And it only took you", tries, "tries!\n"
- raw_input("\n\nPress the enter key to exit.")
Add Comment
Please, Sign In to add comment