May-15-2020, 12:22 AM
I am trying to make a program which tests the user on 10 math questions in random order. The questions and answers with the question number are in the dictionary mathsQs and the options for the answer is in m1 to m10. I am trying to access the embedded keys and values in the mathsQs dictionary so I can print the key and store the answer. I can also use the question number to choose which options to print. It will count the points of the person and can retry if they want at the end.
This is my code:
This is my code:
import random test = True points = 0 mathsQs = {1:{"17 * 3":"c"}, 2:{"3² * √36":"a"}, 3:{"(20% * 50)(10% * 100)":"d"}, 4:{"(5*5)* 40%":"d"}, 5:{"Is 30% of 150 bigger smaller or equal to 15% of 300?":"c"}, 6:{"17 * 6":"a"}, 7:{"5² * √400":"c"}, 8:{"(4/5)(15/28)":"b"}, 9:{"12% of 32":"d"}, 10:{"102/(34*1.5)":"d"}} m1 = {"a":54, "b":51, "c":21, "d":49} m2 = {"a":54, "b":51, "c":21, "d":49} m3 = {"a":87, "b":110, "c":91, "d":100} m4 = {"a":32, "b":10, "c":100, "d":8} m5 = {"a":"Smaller", "b":"Equal to", "c":"Equal to"} m6 = {"a":102, "b":98, "c":100, "d":149} m7 = {"a":245, "b":435, "c":500, "d":600} m8 = {"a":5/7, "b":3/7, "c":2/9, "d":1/3} m9 = {"a":4, "b":5.55, "c":9.17, "d":3.84} m10 = {"a":1.73, "b":1.9649122807 , "c":1.98039215686 , "d":2} while test == True: print("") print("Welcome to the maths quiz") for i in range(10): num = random.randint(1,10) q, ans = list(mathsQs.get(num)) print(q) print(ans)