Python函数的问题

时间:2013-05-12 02:27:17

标签: python function

我正在使用python制作一个命令行程序来计算线性方程式的东西。 我的一个函数声明是这样的:

def lineSub():
  while true:
    print("This is the Linear Equation submenu")
    print("Choose and option")
    print("0: exit")
    print("1: input 'm' and 'b' in y=mx+b")
    print("2: input 'a' , 'b' and 'c' in ax+by=c")
    print("3: input a point and a slope") 
    print("4: input two points")
    choice = getInt("Choice: ")
    lineSM = {
      1: yIntForm,
      2: stdForm,
      3: pointSlope,
      4: twoPoints,
    }
    if choice == 0:
      return 0 
    elif not(choice in range(0,5)):
      print("That's not a choice")
    else:  
      lineSM[choice]()

该选择使用户进入子菜单功能。 每次我运行程序时都会显示该行

def lineSub():

语法无效。 我不知道它有什么问题,所有其他功能定义完全相同,并没有显示任何错误。 请帮忙!

1 个答案:

答案 0 :(得分:3)

你可能在此之前缺少一个结束括号或类似的东西。

例如:

def myfunc():
    print("I forgot the closing parenthesis here--->"

def lineSub():
  while True:
    print("This is the Linear Equation submenu")

由于python忽略括号内的换行符,因此看起来错误的语法位于def lineSub()行。