Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice, randint
- COUNTER = 0
- LEVEL = 0
- def check(Num):
- global COUNTER
- global LEVEL
- while True:
- try:
- value = int(input("Please enter your Answer: "))
- except ValueError:
- print("Sorry I dont understand that")
- continue
- else:
- break
- if Num == value:
- print("Well Done")
- COUNTER += 1
- else:
- print("You are Wrong it should be : ", Num)
- COUNTER -= 1
- LEVEL = COUNTER // 3
- LEVEL = max(0, min(5, LEVEL)) # restrict to 0 <= LEVEL <= 5
- while True:
- try:
- c = input("Do you wish to continue? Y/N: ")
- if c.upper() == 'Y':
- return 1
- elif c == "N":
- return setUp()
- except ValueError:
- print("Try again")
- continue
- def setUp():
- global LEVEL
- print("Select one of the following options: ")
- while True:
- try:
- key = int(input("(1) Addition (2) Subtraction (3) Multiplication \n"
- + "(4) Division (5) Random sums (6) Quit\n"))
- break
- except ValueError:
- print('Bad input!')
- continue
- while True:
- select = key
- if key == 5:
- select = randint(1, 4)
- num1 = randint(1, 4 + LEVEL)
- num2 = randint(1, 4 + LEVEL)
- dic = {1: num1 + num2, 2: num1 - num2, 3: num1 * num2, 4: None, 5: None}
- support = {1: "+", 2: "-", 3: "*", 4: "/"}
- if select != 4 and select != 2 and select!=6:
- print("what is the answer for : {} {} {}".format(num1, support[select], num2))
- if select == 6:
- print("Have a good day")
- exit()
- elif select not in dic:
- print("Invalid choice.")
- break
- elif 1 <= select <= 3 or select == 5:
- if select == 2:
- num3 = randint(1, num1)
- print("what is the answer for : {} {} {}".format(num1, "-", num3))
- res = check(num1 - num3)
- else:
- res = check(dic[select])
- else:
- div = [element for element in range(1, num1 + 1) if num1 % element == 0]
- num2 = choice(div)
- print(f'What is the answer for: {num1} / {num2}')
- res = check(num1 / num2)
- if res == 0: #
- break # we quit the while True
- # back to the top of while True
- setUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement