Queer European MD passionate about IT

professor.py 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import random
  2. def main():
  3. # random.seed() # This breaks check50 😠
  4. score = 0
  5. level = get_level()
  6. for _ in range(10):
  7. x = generate_integer(level)
  8. y = generate_integer(level)
  9. for _ in range(3):
  10. try:
  11. answer = int(input(f"{x} + {y} ="))
  12. except (ValueError, TypeError):
  13. answer = -1
  14. if answer == x + y:
  15. score += 1
  16. break
  17. else:
  18. print("EEE")
  19. else:
  20. print(f"{x} + {y} = {x + y}")
  21. print(f"Score: {score}")
  22. def get_level():
  23. level = 0
  24. while level not in (1, 2, 3):
  25. try:
  26. level = int(input("Level: "))
  27. except (ValueError, TypeError):
  28. level = 0
  29. return level
  30. def generate_integer(level):
  31. if level not in (1, 2, 3):
  32. raise ValueError
  33. return random.randint((10**(level - 1) if level > 1 else 0), 10**level - 1)
  34. if __name__ == "__main__":
  35. main()