I am quite confused about what is wrong with my code. I am trying to make a math practice program. However, when I choose an operation, no matter what I type in, it will always take me to addition. Can someone please help me solve this problem. My little brother is not very excitedly waiting. :)
from random import randint
print("Welcome to Luke's Math Practice")
score = 0
def mathAddition():
global score
numberOne = randint(0, 100)
numberTwo = randint(0, 100)
answer = input(f"{numberOne} + {numberTwo} = ")
correctAnswer = numberOne + numberTwo
if int(answer) == correctAnswer:
print("Correct!")
score = score + 1
elif int(answer) != correctAnswer:
print("Incorrect!")
print("The Correct Answer was", correctAnswer)
print("Your Score Is:", score)
choiceOperation()
else:
print("Sorry That Was an Invalid Answer")
def mathSubtraction():
global score
numberOne = randint(0, 100)
numberTwo = randint(0, 100)
answer = input(f"{numberOne} - {numberTwo} = ")
correctAnswer = numberOne - numberTwo
if int(answer) == correctAnswer:
print("Correct!")
score = score + 1
elif int(answer) != correctAnswer:
print("Incorrect!")
print("The Correct Answer was", correctAnswer)
print("Your Score Is:", score)
choiceOperation()
else:
print("Sorry That Was an Invalid Answer")
def mathMultiplication():
global score
numberOne = randint(0, 20)
numberTwo = randint(0, 20)
answer = input(f"{numberOne} * {numberTwo} = ")
correctAnswer = numberOne * numberTwo
if int(answer) == correctAnswer:
print("Correct!")
score = score + 1
elif int(answer) != correctAnswer:
print("Incorrect!")
print("The Correct Answer was", correctAnswer)
print("Your Score Is:", score)
choiceOperation()
else:
print("Sorry That Was an Invalid Answer")
def mathDivision():
global score
numberOne = randint(0, 20)
numberTwo = randint(0, 20)
answer = input(f"{numberOne} / {numberTwo} = ")
correctAnswer = numberOne / numberTwo
if int(answer) == correctAnswer:
print("Correct!")
score = score + 1
elif int(answer) != correctAnswer:
print("Incorrect!")
print("The Correct Answer was", correctAnswer)
print("Your Score Is:", score)
choiceOperation()
else:
print("Sorry That Was an Invalid Answer")
def choiceOperation():
operationChoice = input("Would you like to practice adding, subtracting, multiplying, or dividing? ")
if operationChoice == "add" or "+" or "adding" or "addition":
while True:
mathAddition()
elif operationChoice == "subtract" or "-" or "subtracting" or "subtraction":
while True:
mathSubtraction()
elif operationChoice == "multiply" or "*" or "x" or "multipying" or "multiplication":
while True:
mathMultiplication()
elif operationChoice == "divide" or "/" or "dividing" or "division":
while True:
mathDivision()
else:
print("Sorry, That Was an Invalid Choice")
choiceOperation()
No comments:
Post a Comment