I have made a mental Maths game but it seems quite long, is there anyway in which I can simplify it? And can you also help me with my other Maths game, Ten quick questions ?
correctq=0
actualanswer = 0
print("Welcome to Mental Maths")
print("If you chose Division rpund down to the nearest whole number")
mode = input("(A)ddition, (S)ubtraction, (M)ultiplication or (D)ivision?")
hardness = input("(E)asy, (M)edium or (H)ard?")
questions=int(input("Enter the amount of questions:"))
if mode == "A":
if hardness == "E":
from random import randint
for i in range(questions):
number1 = randint(1,100)
number2 = randint(1,100)
questionno = i + 1
answer = int(input(str(questionno) +": " + str(number1) + " + "+ str(number2) + " = "))
actualanswer = number1 + number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "M":
from random import randint
for i in range(questions):
number1 = randint(100,1000)
number2 = randint(100,1000)
questionno = i + 1
answer = int(input(str(questionno) + ": " + str(number1)+ " + " + str(number2) + " = "))
actualanswer = number1 + number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "H":
from random import randint
for i in range(questions):
number1 = randint(1000,10000)
number2 = randint(1000,10000)
questionno = i + 1
answer = int(input(str(questionno)+": "+str(number1) + " + " + str(number2) + " = "))
actualanswer = number1 + number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
else:
print("Please enter the letter E, M or H, nothing else")
elif mode == "S":
if hardness == "E":
from random import randint
for i in range(questions):
number1 = randint(50,100)
number2 = randint(1,50)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " - "+ str(number2) + " = "))
actualanswer = number1 - number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "M":
from random import randint
for i in range(questions):
number1 = randint(500,1000)
number2 = randint(100,500)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " - "+ str(number2) + " = "))
actualanswer = number1 - number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "H":
from random import randint
for i in range(questions):
number1 = randint(5000,10000)
number2 = randint(1000,5000)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " - "+ str(number2) + " = "))
actualanswer = number1 - number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
else:
print("Please enter the letter E, M or H, nothing else")
elif mode == "M":
if hardness == "E":
from random import randint
for i in range(questions):
number1 = randint(1,10)
number2 = randint(1,5)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " x "+ str(number2) + " = "))
actualanswer = number1 * number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "H":
from random import randint
for i in range(questions):
number1 = randint(50,100)
number2 = randint(1,50)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " x "+ str(number2)+ " = "))
actualanswer = number1 * number2
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "M":
from random import randint
for i in range(questions):
number1 = randint(5,20)
number2 = randint(1,15)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1) + " x " + str(number2) + " = "))
actualanswer = number1 * number2
if actualanswer == answer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was "+actualanswer)
else:
print("Please enter the letter E, M or H, nothing else")
elif mode == "D":
if hardness == "E":
from random import randint
for i in range(questions):
number1 = randint(10,100)
number2 = randint(1,10)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " ÷ "+ str(number2) + " = "))
actualanswer = number1 / number2
actualanswer=int(actualanswer)
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "M":
from random import randint
for i in range(questions):
number1 = randint(50,200)
number2 = randint(10,50)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " ÷ "+ str(number2) + " = "))
actualanswer = number1 / number2
actualanswer=int(actualanswer)
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
elif hardness == "H":
from random import randint
for i in range(questions):
number1 = randint(100,500)
number2 = randint(50,100)
questionno=i+1
answer = int(input(str(questionno)+": "+str(number1)+ " ÷ "+ str(number2) + " = "))
actualanswer = number1 / number2
actualanswer=int(actualanswer)
if answer == actualanswer:
print("Correct!")
correctq = correctq + 1
else:
print("Wrong, the answer was ", actualanswer)
else:
print("Please enter the letter E, M or H, nothing else")
else:
print("Please enter the lettr A, S, M or D, nothing else")
print("You got " + str(correctq) + " qustions right out of " + str(questions))