Python代码不会打印程序的结果

时间:2017-10-04 03:13:18

标签: python if-statement while-loop

不确定发生了什么,但我无法让程序打印结果。 目标是设计一个程序,我可以找出偿还贷款需要多少个月以及支付多少利息。如果付款超过本金,也要防止贷款过高。任何帮助表示赞赏:

principal = float(input("Principal-------- "))
annual_interest = float(input("Annual Interest-- "))
monthly_payment = float(input("Monthly Payment-- "))
interest_month = (annual_interest/12)/100

months = 0
actual_payment = 0
total_payment = 0
interest_total = 0

interest_calc = interest_month*principal
interest_total = interest_calc+interest_total


if monthly_payment<interest_total:
    print()
    print("Loan Not Approved.")
else:
    interest_calc = 0
    interest_total = 0
    while principal >= 0:
        months= months + 1
        interest_calc = interest_month * principal
        interest_total= interest_calc + interest_total
        actual_payment= monthly_payment - interest_calc
        if actual_payment > principal:
            actual_payment = principal
        total_payment = actual_payment + total_payment
        principal = principal - actual_payment



    print()
    print("Months   : ",months)
    print("Interest :  $%.2f"%(interest_total))

1 个答案:

答案 0 :(得分:0)

而不是当主要&gt; = 0时,使用while principal&gt; 0

本金金额总是等于0,因为对于最后一次付款,实际付款=本金,所以你的代码卡在了while循环中。

相关问题