为什么我在这段代码中得到了无效的语法错误,Python?

时间:2015-05-22 07:30:47

标签: python list append tuples

代码:

students = []
choice = None
while choice != 0:

      print(
    """
    0 - Exit
    1 - Show all students
    2 - Add a student
    """
    )
      choice = input("Choice: ")
      print()
      if choice == "0":
          print("Goodbye")
          break
      elif choice == "1":
           print("\nStudents: ")
           for entry in students:
                 email, name, number = entry
                 print(name, "\t", email, "\t", number)
      elif choice == "2":
          name = input("What is the students name?")
          email = input("What is the students email adress? ")
          number = int(input("What is the students number? ")      
          entry = email, name, number
          students.append(info)
          students.sort(reverse=False)
          student = students
      else:
          print("Sorry, but", choice, "isn't a valid choice.")

当我在编译器中运行它时,我得到了行

的语法错误
entry = email, name, number

我不知道为什么,请告诉我。

1 个答案:

答案 0 :(得分:4)

错误行上方的行上缺少)

number = int(input("What is the students number? ")  #here 
entry = email, name, number

通常,缺少括号会导致堆栈跟踪指向紧随其后的行。