Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python打印显示_Python 3.x - Fatal编程技术网

Python 3.x Python打印显示

Python 3.x Python打印显示,python-3.x,Python 3.x,我对我正在工作的这个项目有问题。我的问题是,在我的显示列表的末尾,我得到了一个负数,所以我想知道是否有人可以给我一些关于如何解决这个问题的指导?我需要它是零 InitalPrice = float(input("Enter the Price of the Computer: ")) Month = 0 DownPayment = InitalPrice * .10 Balance = (InitalPrice - DownPayment) AnInterest = Balance * .01

我对我正在工作的这个项目有问题。我的问题是,在我的显示列表的末尾,我得到了一个负数,所以我想知道是否有人可以给我一些关于如何解决这个问题的指导?我需要它是零

InitalPrice = float(input("Enter the Price of the Computer: "))
Month = 0
DownPayment = InitalPrice * .10
Balance = (InitalPrice - DownPayment)
AnInterest = Balance * .01 / 12
MonthlyPayment = Balance * 0.05 

print("%0s%20s%20s%20s%13s%23s" %("Month", "Current Balance", "Interest 
Owed", "Principal Owed", "Payment", "Balance Remaining"))


for i in range(1, 100): 
    #AnInterest = AnInterest
    if Balance >= 0:
        InitalPrice = InitalPrice - InitalPrice * .10 

        Principal = MonthlyPayment - AnInterest
        Balance = Balance + AnInterest - MonthlyPayment
        print("%0d%20.2f%20.3f%20.2f%13.2f%23.2f" %(i, InitalPrice, AnInterest, Principal, MonthlyPayment, Balance))

您正在减去一个固定金额作为每月付款(即余额的10%)。如果余额加上利息少于该月付款,则余额为负。你只需要做一个简单的检查,看看情况是否如此


另外,我建议只使用while循环来解决这个问题,因为for循环可能迭代太多次,或者迭代次数不够。

好的,非常感谢。