這是我計算信用卡餘額的程序。它適用於大多數輸入,但是當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