0

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")
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Daniel
  • 47
  • 4
  • Please reduce and enhance this into the expected [MRE](https://stackoverflow.com/help/minimal-reproducible-example). Your code hangs waiting for input; we expect you to provide this in the code, not make us write test data. Also, most of this code is unnecessary for whatever syntax problem you hvae. – Prune May 11 '20 at 02:45
  • Does this answer your question? [Python 3 returns "invalid syntax" when trying to perform string interpolation](https://stackoverflow.com/questions/42126794/python-3-returns-invalid-syntax-when-trying-to-perform-string-interpolation) – Gino Mempin May 11 '20 at 04:12
  • your code is running fine in my computer, please make sure you run this code with python version > 3.6 – Nam Phuong May 11 '20 at 02:49
  • I am telling this as a answer, even though it is a comment, because I do not have enough reputations to comment, but I think the problem is that your program is being runned on an older version. The version that I used to check your code is 3.8.1, which I thinks allows f strings. – TheMatrix May 11 '20 at 02:47

0 Answers0