Guest User

Untitled

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