2015-11-28 98 views
0

我目前正在努力完成我的课程,出于某种原因,我一直在获取无效的语法。不工作的部分是一流的,不,它最初的工作,但现在已经停止,所以我不知道这是否是我的软件或东西..我的代码如下:无效的语法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() 
+0

请包括实际输出。 –

+0

排序出队友 – jazzathecutts

回答

0

你有多余的括号在这些行上

print("Hello, " + name+(". Welcome to the Arithmetic Quiz") # line 6 | open bracket 

classno = input("What class are you in?")) # line 8 | close bracket 

您还没有在任何地方定义group。我想你的意思是说

while classno not in classnumber: 
+0

谢谢,新的python。 – jazzathecutts

+0

一切都好。有时候错误会解释很多,有时候不会。我将指出几件事情,并会在一秒钟内加入回答。 –

+0

如果您发现此回答适当地回答您的问题,那么您可以接受您的问题的答案。 –