我收到“ SyntaxError:无效语法”,但没有发现任何错误

时间:2020-05-11 02:37:13

标签: python python-3.x syntax-error

使用mimir时收到此消息:

File "./CS902Module6Homework1.py", line 56  
   print (f"Name is: {Names[foundaposition]} \n{Names[foundaposition]} account has the balance of : {balance[foundaposition]}")


SyntaxError: invalid syntax

程序正常运行,第56行代码正确显示了输出。

我的语法不正确吗?

Names=[]
accountnumbers=[]
balance=[]

def populatelist():
 position=0
 while(position<=1):
   yourname= str(input("Please enter a name: "))
   Names.append(yourname)
   account = int(  input("Please enter an account number: " ))
   accountnumbers.append(account)
   totalbalance = int(  input("Please enter a balance: "))
   balance.append(totalbalance)
   position = position + 1

def findingaccount(accountnumber):
 foundposition=-1
 position=0
 if (len(accountnumbers)>0):
  while (position <=1):
   if (accountnumber==accountnumbers[position]):
    return position
 position = position + 1
 return foundposition

def menuoptions():
   print ("**** MENU OPTIONS ****")
   print ("Type P to populate accounts")
   print ( "Type S to search for account")
   print ("Enter E to exit")
   choice = str(input("Please enter your choice: "))
   return choice

response=""
while response!= "E":

 response = menuoptions()
 if response=="P":
   populatelist()

 elif response=="S":
  searchaccount = int(input("Please enter the account number to search:  "))
  foundaposition = findingaccount(searchaccount)
  if ( foundaposition == -1 ):
   print ("The account number not found!")
  else:
   print(f"Name is: {Names[foundaposition]} \n{Names[foundaposition]} account has the balance of :{balance[foundaposition]}")

 elif response=="E":
  print ("Thank you for using the program")
  print ("Bye")
  exit

 else:
  print ("invalid choice. Please try again")

1 个答案:

答案 0 :(得分:2)

我说这是一个答案,尽管它是注释,因为我没有足够的声誉来注释,但是我认为问题是您的程序正在较旧的版本上运行。我用来检查代码的版本是3.8.1,我认为它允许f字符串。

相关问题