这是我计算信用卡余额的程序。它适用于大多数输入,但是当balance
变得太大时,程序运行一个无限循环。可以做些什么来改进代码,以便计算更大的值?为什么在这个程序中大数值导致无限循环?
monthlyPayment = 0
monthlyInterestRate = annualInterestRate /12
newbalance = balance
month = 0
while newbalance > 0:
monthlyPayment += .1
newbalance = balance
for month in range(1,13):
newbalance -= monthlyPayment
newbalance += monthlyInterestRate * newbalance
month += 1
print("Lowest Payment:" + str(round(monthlyPayment,2)))
我们仍然不知道'annualInterestRate'的价值 – heltonbiker