我目前正在努力完成我的課程,出於某種原因,我一直在獲取無效的語法。不工作的部分是一流的,不,它最初的工作,但現在已經停止,所以我不知道這是否是我的軟件或東西..我的代碼如下:無效的語法erroe python
import random
score = 0
questions = 0
classnumber = ("1","2","3")
name= input("Enter Your Username: ")
print("Hello, " + name+(". Welcome to the Arithmetic Quiz")
classno = input("What class are you in?"))
while group not in classnumber:
print("Enter a valid class")
classno=input("What class are you in?")
while questions <10:
for i in range(10):
number1=random.randint(1,10)
number2=random.randint(1,10)
op=random.choice("*-+")
multiply=num1*num2
subtract=num1-num2
addition=num1+num2
if op == "-":
print("Please enter your answer.")
questions+=1
print(" Question" ,questions, "/10")
uinput=input(str(number1)+" - "+str(number2))
if uinput == str(subtract):
score+=1
print("Correct, your score is: " ,score,)
else:
print ("Incorrect, the answer is: " +str(subtract))
score+=0
if op == "+":
print("Please enter your answer.")
questions+=1
print(" Question",questions, "/10")
uinput=input(str(number1)+" + "+str(number2))
if uinput == str(addition):
score+=1
print(" Correct, your score is: ",score,)
else:
print(" Incorrect, the answer is: " +str(addition))
score+=0
if op == "*":
print("Please enter you answer.")
questions+=1
print(" Question",questions, "/10")
uinput=input(str(number1)+" * "+str(number2))
if uinput == str(multiply):
score+=1
print(" Correct, your score is: " ,score,)
else:
print(" Incorrect, the answer is: " +str(multiply))
score+=0
if score >9:
print("Well done," ,name1, "your score is" ,score, "/10")
else:
print(name1," your score is " ,score, "/10")
def no1():
with open("class1.txt", 'a')as file:
file.write(str(name1)+str(score)+"\n")
def no2():
with open("class2.txt", 'a')as file:
file.write(str(name1)+str(score)+"\n")
def no3():
with open("class3.txt", 'a')as file:
file.write(str(name1)+str(score)+"\n")
if group=="1":
no1()
if group=="2":
no2()
if group=="3":
no3()
請包括實際輸出。 –
排序出隊友 – jazzathecutts