直到我的程序中有一个错误,我才把我的程序中的错误记录下来。我已经添加了下面的代码,所以请帮助我这一点,并建议我如何改进我的代码,以避免收到此错误消息。在import random
def questions():
name=input("What is your name: ")
print("Hello there",name,"! Please answer 10 random maths questions for this test!")
Class=input("Which class are you in?")
choice = random.choice("+-x")
finish = False
questionnumber = 0
correctquestions = 0
while finish == False:
choice = random.choice("+-x")
if questionnumber < 10 | questionnumber >= 0:
number1 = random.randrange(1,10)
number2 = random.randrange(1,10)
print((number1),(choice),(number2))
answer=int(input("What is the answer?"))
questionnumber = questionnumber + 1
if choice==("+"):
realanswer = number1+number2
if answer==realanswer:
print("That's the correct answer")
correctquestions = correctquestions + 1
else:
print("Wrong answer, the answer was",realanswer,"!")
if choice==("x"):
realanswer = number1*number2
if answer==realanswer:
print("That's the correct answer")
correctquestions = correctquestions + 1
else:
print("Wrong answer, the answer was",realanswer,"!")
elif choice==("-"):
realanswer = number1-number2
if answer==realanswer:
print("That's the correct answer")
correctquestions = correctquestions + 1
else:
print("Wrong answer, the answer was",realanswer,"!")
else:
finish = True
else:
print("Good job",name,"! You have finished the quiz")
print("You scored " + str(correctquestions) + "/10 questions.")
if ClassOfStudent==1:
Class=open('N:Class 1 Score.txt','a')
Class.write(name)
Class.write(str(correctquestions))
Class.close()
if ClassOfStudent==2:
Class=open('N:Class 2 Score.txt','a')
Class.write(name)
Class.write(str(correctquestions))
Class.close()
if ClassOfStudent==3:
Class=open('N:Class 3 Score.txt','a')
Class.write(name)
Class.write(str(correctquestions))
Class.close()
questions()