I have no idea why this code is not working, as you can see I'm trying to ask the user 10 questions display their score at the end. Everything works except that the score will always appear as a 0
or 1
at the end, even if more than 1
question was answered right.
Here is my code:
import random
studentname=input("what is your name?:")
def question():global operationglobal number1global number2global studentanswerglobal scoreoperation=random.choice(["*","-","+"])score=0trueanswer=0number1=random.randrange(1,10)number2=random.randrange(1,10)print("what is", number1,operation,number2,"?:")studentanswer=int(input("insert answer:"))def checking():global scoreif operation == "*":trueanswer = number1*number2if studentanswer == trueanswer:print("correct")score=score+1else:print("incorrect")score=scoreelif operation == "-":trueanswer = number1-number2if studentanswer == trueanswer:print("correct")score=score+1else:print("incorrect")score=scoreelif operation == "+":trueanswer = number1+number2if studentanswer == trueanswer:print("correct")score = score+1else:print("incorrect")score=scoredef main():for i in range (10):question()checking()print("your score is", score)main()