Home > OS >  how can i fix my code to give the calculated cash amount plus interest rate as a finale result
how can i fix my code to give the calculated cash amount plus interest rate as a finale result

Time:12-11

i can't get my code to work. i keek getting TypeError: unsupported format string passed to function.__format

my code that I tried is below:

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

CodePudding user response:

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

CodePudding user response:

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

CodePudding user response:

I think I solved it for you, I don't understand why you put the brackets inside {money:.2f} I don't know what you mean by :.2f. I put it outside the brackets for you to print. the error was in :.2f in a {}

# in a f'' you include :.2f in {} 
def formatCurrency(money):
    moneyString = f'${money}:.2f'
    return moneyString


# error in a return "you return the name of fun instead amount"
def updateBalance(amount, interest):
    amount = (1 (interest*1))
    return amount

### 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))
  • Related