Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def main():
- r=get_level()
- score=0
- for i in range(10):
- if i == 10:
- break
- else:
- p=generate_integer(r)
- x=p[0]
- y=p[1]
- for i in range(3):
- try:
- answer=int(input(f"{x} + {y} = "))
- except ValueError:
- print("EEE")
- continue
- if x+y == answer:
- score +=1
- break
- elif x+y != answer:
- print("EEE")
- continue
- else:
- print(f"{x} + {y} = {x+y}")
- i+=1
- print(f"Score:{score}")
- def get_level():
- while True:
- try:
- n = int(input("Level: "))
- if n == 1 or n == 2 or n== 3:
- break
- else:
- continue
- except ValueError:
- continue
- return n
- def generate_integer(level):
- if level== 1:
- x = random.randint(0, 9)
- y = random.randint(0, 9)
- return x,y
- elif level == 2:
- x = random.randint(10, 99)
- y = random.randint(10, 99)
- return x,y
- elif level == 3:
- x = random.randint(100, 999)
- y = random.randint(100, 999)
- return x,y
- if __name__ == "__main__":
- main()
Comments
-
- https://www.reddit.com/r/cs50/comments/xx1cbe/can_someone_help_me_with_the_little_professor/
Add Comment
Please, Sign In to add comment