编写一个函数,用于在给定的年数之后计算具有给定初始余额和利率的银行帐户的余额。假设每年的利息都是复合的。使用Python函数计算复合利息
我有错误“ValueError异常:不支持的格式字符‘I’,在指数28(×49)”
这里是我到目前为止的代码。
def BankBalance():
InputB = 1000
return InputB
print("Your initial balance is $1000")
def Interest():
InputI = 0.05
return InputI
print("The rate of interest is 5%")
def CountNumber():
InputN = float(input("Please enter the number of times per year you would like your interest to be compounded: "))
return InputN
def Time():
InputT = float(input("Please enter the number of years you need to compund interest for:"))
return InputT
def Compount_Interest(InputB, InputI, InputT, InputN):
Cinterest = (InputB*(1+(InputI % InputN))**(InputN * InputT))
print("The compound interest for %.InputT years is %.Cinterest" %Cinterest)
B = BankBalance()
I = Interest()
N = CountNumber()
T = Time()
Compount_Interest(B, I, N, T)
你需要一个'''之间和InputB''(1 +(InputI',像这样:'Cinterest =(InputB *(1+(InputI%InputN))**(InputN * InputT) )' – javanut13