2015-11-28 133 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

如果您發現此回答適當地回答您的問題,那麼您可以接受您的問題的答案。 –