提问人:Ian Schaak 提问时间:11/6/2023 更新时间:11/6/2023 访问量:10
利息的最后一个值应为零 While 循环
Last value for interest should be zero While loop
问:
我正在做一个标准的家庭作业,但我无法把最后一件小事做好。
print("Enter the purchase price:")
purchasePrice = input()
purchasePrice = float(purchasePrice)
downPayment = purchasePrice * 0.10
monthlyPayment = (purchasePrice - downPayment) * 0.05
annualInterestPayment = purchasePrice * 0.12
month = 0
balance = purchasePrice - downPayment
print("the purchase price is", purchasePrice)
print("the down payment is", downPayment)
print("the monthly payment is", monthlyPayment)
print("the annual interest is", annualInterestPayment)
#print("012345678901234567890")
print("%0s%20s%20s%20s%11s%22s" %("Month","Starting Balance","Interest to Pay","Principal to Pay","Payment","Ending Balance"))
#first %#s marks how far in it will go.
#with the h in month being placed where the number in %#s indicates
while balance >= 0.0:
month += 1
currentBalance = balance
currentInterest = (currentBalance * 0.12)/12
currentPrincipal = monthlyPayment-currentInterest
endingBalance = currentBalance - currentPrincipal
print("%0d%20.2f%20.3f%20.2f%13.2f%23.2f" %(month, currentBalance, currentInterest, currentPrincipal, monthlyPayment, endingBalance))
balance = endingBalance
它在大多数情况下有效,我不知道该怎么做才能使最后的利息值为零。我尝试过的所有解决方案都使它成为一个无限循环。
答: 暂无答案
下一个:循环内循环 [重复]
评论