-1
我无法从这个页面 Here初学者的Python行使
这里是我的代码解决问题2:
#Problem set 1 b
out_bal = float(raw_input("Enter the outstanding balance on your credit card: "))
ann_interest = float(raw_input("Enter the annual interest rate as a decimal: "))
min_pmnt = 10
months = 1
prev_bal = out_bal
month_interest = ann_interest/12.0
updated_bal = prev_bal * (1 + month_interest) - min_pmnt
while out_bal > 0:
for i in range(1,13):
out_bal = updated_bal
prev_bal = out_bal
months += 1
if out_bal <= 0:
break
else:
min_pmnt = min_pmnt + 10
months = 0
print out_bal
print "RESULT"
print "Monthly payment to pay off debt in 1 year: $", min_pmnt
print "Number of months needed: ", months
print "Balance: ", round(out_bal, 2)
我想利用1200和0.18的前两个输入,分别。但是,当我这样做时,程序会在我的while循环中被捕获并保持打印1208.00。
当我看到自己的代码,它似乎应该工作。但我想我没有正确使用prev_bal变量。
此外,它执行数学运算的方式,我希望它第一次通过循环,但它看起来好像它没有添加10 min_pmnt并再次通过循环。它似乎只是反复使用10次。
我怎么写这个,所以它实际上添加10并再次执行循环?
谢谢!