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

Python代码不会打印程序的结果,python,if-statement,while-loop,Python,If Statement,While Loop,不确定发生了什么,但我无法让程序打印结果。 我们的目标是设计一个程序,在这个程序中,我可以知道还清贷款需要多少个月,以及支付了多少总利息。此外,如果付款额超过本金,还应防止过度支付贷款。感谢您的帮助: principal = float(input("Principal-------- ")) annual_interest = float(input("Annual Interest-- ")) monthly_payment = float(input("Monthly Payment--

不确定发生了什么,但我无法让程序打印结果。 我们的目标是设计一个程序,在这个程序中,我可以知道还清贷款需要多少个月,以及支付了多少总利息。此外,如果付款额超过本金,还应防止过度支付贷款。感谢您的帮助:

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))
principal=float(输入(“principal------”)
年利息=浮动(输入(“年利息-”)
月付款=浮动(输入(“月付款-”)
利息月=(年利息/12)/100
月份=0
实际付款=0
付款总额=0
利息总额=0
利息计算=利息月*本金
利息总额=利息计算+利息总额
如果每月付款=0:
月数=月数+1
利息计算=利息月*本金
利息总额=利息计算+利息总额
实际付款=每月付款-利息计算
如果实际付款>本金:
实际付款=本金
总付款=实际付款+总付款
委托人=委托人-实际付款
打印()
打印(“月:”,月)
打印(“利息:$%.2f”%(利息总额))

使用while principal>0而不是while principal>=0


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

使用while principal>0,而不是while principal>=0

本金金额最终将始终等于0,因为对于最后一次付款,实际付款=本金,因此您的代码卡在while循环中