Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import random
  2.  
  3. tree = int(0)
  4. print('tree = 0')
  5.  
  6. #the code below is the main game and code block
  7. def main():
  8. number = random.randrange(100)
  9. number = int(number)
  10. tries = 1
  11. guess = input('\nGuess a number..\n')
  12.  
  13. while int(number) != int(guess):
  14.  
  15. if int(number) < int(guess):
  16. guess = input('Too high, try again...\n')
  17. else:
  18. guess = input('Too low, try again...\n')
  19. tries += 1
  20.  
  21. print('\nWell done, you guessed the number in ' + str(tries) + ' tries')
  22.  
  23. tries = int(tries)
  24.  
  25. if tree == 0:
  26. bestscore = 100
  27. tree = 1
  28.  
  29. if int(tries) <= bestscore:
  30. bestscore = int(tries)
  31. print('New bestscore: ')
  32. print(str(bestscore))
  33. else:
  34. print('Bestscore: ')
  35. print(str(bestscore))
  36.  
  37. return bestscore
  38.  
  39. #the code below asks the user to play again
  40. def repeat():
  41. repeat = input('Do you want another go? (Y/N): ')
  42. if repeat == "Y":
  43. return True
  44. elif repeat == "y":
  45. return True
  46. elif repeat == "N":
  47. print("Goodbye!")
  48. return False
  49. elif repeat == "n":
  50. print("Goodbye!")
  51. return False
  52. else:
  53. print("Oops, an error occured!")
  54.  
  55. #MAIN METHOD
  56.  
  57. print('GUESS THE NUMBER GAME - BY MUDASSIR AHMED\n')
  58. print('How to play:\n1. Type your guessed number between 0 and 100\n2. Hit enter and see what\'s the result')
  59. reset = True
  60. while reset == True:
  61. tree += 1
  62. main()
  63. reset = repeat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement