Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. # Random Guessing Number
  2.  
  3. def randomNumbers(debugMode="no"):
  4. from random import randint
  5. correct = randint(1,20)
  6. guesses = 0
  7. debugMode = debugMode.lower()
  8. print("I'm thinking of a number between 1 and 20.")
  9. print("You can type \"stop\" at any time to stop.")
  10. if debugMode == "true" or debugMode == "yes":
  11. print("The number is: " + str(correct))
  12. while True:
  13. print("Enter your guess.")
  14. while True:
  15. guess = input(">>> ")
  16. if guess.isdigit() == False and guess.lower() != "quit" and guess.lower() != "stop":
  17. print("Only enter (positive) numbers.")
  18. pass
  19. else:
  20. break
  21. if guess.lower() == "quit" or guess.lower() == "stop":
  22. print("Stopping...")
  23. break
  24. guess = int(guess)
  25. if guess == correct:
  26. guesses += 1
  27. if guesses == 1:
  28. print("You won in %s guess! Good job!" %guesses)
  29. elif guess > 1:
  30. print("You won in %s guesses! Good job!" %guesses)
  31. break
  32. elif guess > correct:
  33. print("Your guess is too high.")
  34. guesses += 1
  35. elif guess < correct:
  36. print("Your guess is too low.")
  37. guesses += 1
  38. else:
  39. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement