maxdimples

Little Professor u/kinchna

Nov 30th, 2022
86
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def main():
  5.  
  6.   r=get_level()
  7.   score=0
  8.   for i in range(10):
  9.     if i == 10:
  10.         break
  11.     else:
  12.       p=generate_integer(r)
  13.       x=p[0]
  14.       y=p[1]
  15.  
  16.  
  17.       for i in range(3):
  18.         try:
  19.           answer=int(input(f"{x} + {y} = "))
  20.         except ValueError:
  21.             print("EEE")
  22.             continue
  23.         if x+y == answer:
  24.             score +=1
  25.             break
  26.         elif x+y != answer:
  27.             print("EEE")
  28.             continue
  29.       else:
  30.         print(f"{x} + {y} = {x+y}")
  31.  
  32.     i+=1
  33.  
  34.  
  35.   print(f"Score:{score}")
  36.  
  37.  
  38.  
  39. def get_level():
  40.   while True:
  41.     try:
  42.       n = int(input("Level: "))
  43.  
  44.       if n == 1 or n == 2 or n== 3:
  45.           break
  46.       else:
  47.           continue
  48.  
  49.     except ValueError:
  50.         continue
  51.  
  52.   return n
  53. def generate_integer(level):
  54.     if level== 1:
  55.       x = random.randint(0, 9)
  56.       y = random.randint(0, 9)
  57.       return x,y
  58.  
  59.     elif level == 2:
  60.       x = random.randint(10, 99)
  61.       y = random.randint(10, 99)
  62.       return x,y
  63.     elif level == 3:
  64.       x = random.randint(100, 999)
  65.       y = random.randint(100, 999)
  66.       return x,y
  67.  
  68.  
  69. if __name__ == "__main__":
  70.     main()
Comments
Add Comment
Please, Sign In to add comment