Guest User

Untitled

a guest
Dec 11th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import random
  2.  
  3. print "\tWelcome to 'Guess My Number'!"
  4. print "\nI'm thinking of a number between 1 and 100."
  5. print "Try to guess it in under 10 attempts.\n"
  6.  
  7. # set the initial values
  8. the_number = random.randrange(100) + 1
  9. # Fixed crash on non numbers
  10. guess = raw_input("take a guess: ")
  11. if (!guess.isdigit())
  12. print "Please enter a valid number"
  13. else:
  14. guess = int(guess)
  15. tries = 1
  16. triesleft = 9
  17.  
  18.  
  19. while (guess != the_number):
  20. if (guess > the_number):
  21. print "Lower..."
  22. print "You have", triesleft, "guesses left!"
  23. else:
  24. print "Higher..."
  25. print "You have", triesleft, "guesses left!"
  26. guess = int(raw_input("Take a guess: "))
  27. tries += 1
  28. triesleft += -1
  29.  
  30.  
  31. if (triesleft == 0):
  32. print "You have lost."
  33. print "You have no more guesses left."
  34. raw_input("\n\nPress the enter key to exit.")
  35. exit()
  36. print "You guessed it! The number was", the_number
  37. print "And it only took you", tries, "tries!\n"
  38.  
  39. raw_input("\n\nPress the enter key to exit.")
Add Comment
Please, Sign In to add comment