Hello. I am interested in coding but i have an assignment which i have been trying to complete but can’t get it to work.
This is the code i havebeen using:
import random
print (“Hello user. What is your name?”)
userName =input()
print (“Hello”, userName , “, You will be tested 10 maths questions”)
questionNumber = 0
score = 0
while questionNumber != 10:
questionPart1 = random.randint(-10,10)
questionPart2 = random.randint(-10,10)
choice = random.randint(0,2)
if choice == 0:
questionAnswer = questionPart1 + questionPart2
print ("What is ",questionPart1, "+", questionPart2, "?")
answer = input()
if input == questionAnswer:
questionNumber = questionNumber + 1
score = score + 1
print ("Congrats, you were right! Currently at", score, "/ 10")
else:
questionNumber = questionNumber + 1
print ("Unfortunately you were wrong. Currently at", score, "/ 10")
if choice == 1:
questionAnswer = questionPart1 - questionPart2
print ("What is ",questionPart1, "-", questionPart2, "?")
input()
if input == questionAnswer:
questionNumber = questionNumber + 1
score = score + 1
print ("Congrats, you were right! Currently at", score, "/ 10")
else:
questionNumber = questionNumber + 1
print ("Unfortunately you were wrong. Currently at", score, "/ 10")
if choice == 2:
questionAnswer = questionPart1 * questionPart2
print ("What is ",questionPart1, "*", questionPart2, "?")
input()
if input == questionAnswer:
questionNumber = questionNumber + 1
score = score + 1
print ("Congrats, you were right! Currently at", score, "/ 10")
else:
questionNumber = questionNumber + 1
print ("Unfortunately you were wrong. Currently at", score, "/ 10")
The code shows 10 questions and prompts the user to answer them, but even if you type the answer in right, it tells me i am wrong and I don’t know why. Any help would be appreciated.