-3

I can't get my code to work. I keek getting:

TypeError: unsupported format string passed to function.__format

Here is the code that I tried:

def formatCurrency(money):
    moneyString = f'${money:.2f}'
    return moneyString
    
    def updateBalance(amount, interest):
    amount = (1+(interest*1))
    return updateBalance



    ### Main Program ###
    savBal = float(input("Enter your savings balance: "))
    chBal = float(input("Enter your checking balance: "))
    savIR = float(input("Enter your saving interest rate %: "))
    chIR = float(input("Enter your checking interest rate %: "))

    savBal = updateBalance(savBal, savIR)
    chBal = updateBalance(chBal, chIR)

    print("Your updated savings balance is" , formatCurrency(savBal))
    print("Your updated checking balance is" , formatCurrency(chBal))
Javad
  • 2,033
  • 3
  • 13
  • 23
  • Your function `updateBalance` returns a reference to itself, not the `amount`. – ddejohn Dec 10 '22 at 23:09
  • i re-wrote my code and now its not giving the right calculations. i changed the defining function to: def updateBalance(amount, interest): amount = amount+(interest/100)*365) return amount – Jamie Lemon Dec 10 '22 at 23:43
  • 1
    Welcome to Stack Overflow! Please make sure you always post full details of errors you run into, such as the line number where the error occurred, and the full traceback. – Hack5 Dec 11 '22 at 15:47

2 Answers2

1

The code is not working with the below error because, in function formatCurrency, the variable value should be of type float, but you are passing a function reference as a return value from updateBalance Function

TypeError: unsupported format string passed to function.format

Replace the function return value with the amount variable and your code will work and solve the issue.

def updateBalance(amount, interest):
    amount = (1+(interest*1))
    return amount
Prudhviraj
  • 441
  • 3
  • 12
0

just a typo error at def updateBalance(amount, interest): amount = (1+(interest*1)) return updateBalance #here's the problem

what you want is: def updateBalance(amount, interest): amount = (1+(interest*1)) return amount