简体   繁体   中英

I am getting “SyntaxError: invalid syntax” I don't see anything wrong

I am getting this message when using a 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

The programs works, the line 56 code displays the output correctly.

How is my syntax not correct?

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")

I am getting this message when using a 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

The programs works, the line 56 code displays the output correctly.

How is my syntax not correct?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM