Guest User

Untitled

a guest
May 4th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | Source Code | 0 0
  1. import random
  2.  
  3.  
  4. def main():
  5. while True:
  6. try:
  7. leveler = int(get_level())
  8. except ValueError:
  9. continue
  10. if leveler in range(1,4):
  11. break
  12. score = 0
  13. # x + y = z
  14. for i in range(10):
  15. tries = 0
  16. question = generate_integer(leveler)
  17. correct_answer = question[0] + question[1]
  18. while True:
  19. print(question[0],'+',question[1],'=',end='')
  20. answer = input(' ')
  21. if answer.isnumeric():
  22. answer = int(answer)
  23. break
  24. else:
  25. print('EEE')
  26. tries +=1
  27. continue
  28. if answer == correct_answer:
  29. if tries < 1:
  30. score+=1
  31. continue
  32. else:
  33. while True:
  34. print('EEE')
  35. print(question[0],'+',question[1],'=',end='')
  36. answer = input(' ')
  37. if not answer.isnumeric():
  38. continue
  39. answer = int(answer)
  40. if answer == correct_answer:
  41. break
  42. else:
  43. continue
  44.  
  45.  
  46. print(f'Score: {score}')
  47.  
  48. def get_level():
  49. level = input("Level: ")
  50. return level
  51.  
  52. def generate_integer(aye):
  53. if aye == 1:
  54. x = random.randint(1,9)
  55. y = random.randint(1,9)
  56. if aye == 2:
  57. x = random.randint(10,99)
  58. y = random.randint(10,99)
  59. if aye == 3:
  60. x = random.randint(100,999)
  61. y = random.randint(100,999)
  62. return (x,y)
  63.  
  64. if __name__ == "__main__":
  65. main()
Advertisement
Add Comment
Please, Sign In to add comment