0
到目前爲止,我一直在編碼這一整個星期試圖讓它工作。貸款計算器程序
應該站出來,因爲這:
Please enter Amount that you would like to borrow(£): 4000
Please enter Duration of the loan(Years):2
Please enter the interest rate (%):6
The total amount of interest for 2 (years) is: £480.00
The total amount of the period for 2 (years) is £4480.00
You will pay £186.67 per month for 24 months.
Do you wish to calculate a new loan payment(Y or N)
代碼:
monthlypayment = 0 #Variable
loanamount = 0 #Variable
interestrate = 0 #Variable
numberofpayments = 0 #Variable
loandurationinyears = 0 #Variable
loanamount = input("Please enter the amount that you would like to borrow(£) ")
loandurationinyears = input("How many years will it take you to pay off the loan? ")
interestrate = input("What is the interest rate on the loan? ")
#Convert the strings into floating numbers
loandurationinyears = float(loandurationinyears)
loanamount = float(loanamount)
interestrate = float(interestrate)
#Since payments are once per month, number of payments is number of years for the loan
numberofpayments = loandurationinyears*12
#calculate the monthly payment based on the formula
monthlypayment = (loanamount * interestrate * (1+ interestrate)
* numberofpayments/((1 + interestrate) * numberofpayments -1))
#Result to the program
print("Your monthly payment will be " + str(monthlypayment))
那麼會出現什麼樣的錯誤?此外,你應該可能將你的利率輸入除以100. – ryugie
它基本上會是一個模糊的數量,如生病6,2,6,它會拿出類似6056235.14291821421542 –
歡迎來到堆棧溢出!我編輯你的問題來修復語法並使其更易讀。另外,我更正了想要的輸出中的推測錯字('&' - >'£')。請[編輯]您的問題以包含完整的實際輸出或發佈的代碼,以便我們有[mcve]。 –