12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import random
- def main():
- # random.seed() # This breaks check50 😠
- score = 0
- level = get_level()
- for _ in range(10):
- x = generate_integer(level)
- y = generate_integer(level)
- for _ in range(3):
- try:
- answer = int(input(f"{x} + {y} ="))
- except (ValueError, TypeError):
- answer = -1
- if answer == x + y:
- score += 1
- break
- else:
- print("EEE")
- else:
- print(f"{x} + {y} = {x + y}")
- print(f"Score: {score}")
- def get_level():
- level = 0
- while level not in (1, 2, 3):
- try:
- level = int(input("Level: "))
- except (ValueError, TypeError):
- level = 0
- return level
- def generate_integer(level):
- if level not in (1, 2, 3):
- raise ValueError
- return random.randint((10**(level - 1) if level > 1 else 0), 10**level - 1)
- if __name__ == "__main__":
- main()
|