在函数中运行时,打印行出现语法错误

时间:2019-02-07 09:08:47

标签: python python-3.x function

def elect():
              global elimed
              elimed = 0
              seats = int(input("\nHow many seats are available? "))
              if seats > 5:
                  print("There are only 5 candidates standing! Please start again.")
                  menu()
              global file
              file = str(input("\nEnter the file path (.txt file) : "))
              if not file.endswith(".txt"):
                  file = file + ".txt"
              if os.path.exists(file) == False:
                  print(file. "not found, Please start again")
                  menu()
              else:
                  print("Selecting file", file)

第12行不断出现语法错误,结尾处带有“。有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您不能在.中使用print(),而应使用,

更改此:

print(file. "not found, Please start again")

对此:

print(file, "not found, Please start again")

或更妙的是,使用format()

print("{}, not found, Please start again".format(file))

答案 1 :(得分:1)

“。”在语法中导致此错误。应该是逗号而不是点。

  

打印(文件,“未找到,请重新开始”)