Guess the number game


SUBMITTED BY: Guest

DATE: Dec. 7, 2014, 3:29 p.m.

FORMAT: Python

SIZE: 1.6 kB

HITS: 1130

  1. import random
  2. import time
  3. def GetNumber():
  4. number = random.randint(0,10)
  5. return number
  6. while True:
  7. y = 1
  8. x = 1
  9. while y == 1:
  10. number = GetNumber()
  11. while x == 1:
  12. print 'Guess the number between 0 and 10'
  13. Guess = input('')
  14. if Guess < 0:
  15. print 'You entered a negative number! The number is not a negative!'
  16. time.sleep(1)
  17. print 'Guess the number between 0 and 10'
  18. time.sleep(1)
  19. elif Guess < number:
  20. print 'Your guess is wrong! You guessed lower than the number'
  21. time.sleep(1)
  22. elif Guess > number:
  23. print 'Your guess is wrong! You guessed higher than the number'
  24. time.sleep(1)
  25. elif Guess == number:
  26. time.sleep(1)
  27. print 'Congratulations! You guessed correctly!'
  28. time.sleep(1)
  29. print 'Would you like to go again?'
  30. print '[1] Yes'
  31. print '[2] No'
  32. answer = input('')
  33. if answer == 1:
  34. break
  35. else:
  36. time.sleep(1)
  37. print 'Thank you for playing! Hope to see you again soon!'
  38. time.sleep(1)
  39. quit()

comments powered by Disqus