我在從Python上創建的表中添加某些值時遇到了一些麻煩。
我的文本文件看起來像:從文本文件創建表格並添加列
E5345,22/09/2015,C106,815,A,400
E5348,23/09/2015,C109,370,A,200
E5349,25/09/2015,C110,480,A,250
E5353,28/09/2015,C114,272,A,200
E5363,01/10/2015,C124,930,A,500
E5364,02/10/2015,C125,915,A,800
E5365,02/10/2015,C126,1486,A,1486
E5366,03/10/2015,C127,576,E,0
E5367,03/10/2015,C128,427,A,350
E5373,10/10/2015,C134,1023,A,550
我希望創建使用這些值在蟒蛇一個表,並創建另一個列,標題爲優秀金額。我已經設法做到這一點,但我想找到未付款的總和。這是通過執行第四列(finaltotal
)減去第六列而找到的。 (amountpaid
)。
到目前爲止我的代碼是:
headers = ["| Estimate Number", "| Date", "| Customer Number", "| Final Total", "| Status", "| Amount Paid", "| Outstanding Amount"]
print(" ".join(headers))
print ("\n-------------------------------------------------------------------------------------------------------------------------")
data = open("paintingJobs.txt", "r")
info=data.readlines()
data.close()
for li in info:
line = li.strip().split(",")
status=line[4]
finaltotal=int(line[3])
amountpaid=int(line[5])
subtotal = int(line[3]) - int(line[5])
outstanding = (finaltotal) - (amountpaid)
line.append(str(subtotal))
if (amountpaid) < (finaltotal) and status == "A":
for i, word in enumerate(line):
print(word.ljust(len(headers[i - (i > 20)])), end=" " * ((i - (i > 20)) != len(headers) - 1))
print()
print ("-------------------------------------------------------------------------------------------------------------------------")
print ("\nThe total revenue is")
我的理想輸出爲:
| Estimate Number | Date | Customer Number | Final Total | Status | Amount Paid | Outstanding Amount
-------------------------------------------------------------------------------------------------------------------------
E5345 22/09/2015 C106 815 A 400 415
-------------------------------------------------------------------------------------------------------------------------
E5348 23/09/2015 C109 370 A 200 170
-------------------------------------------------------------------------------------------------------------------------
E5349 25/09/2015 C110 480 A 250 230
-------------------------------------------------------------------------------------------------------------------------
E5353 28/09/2015 C114 272 A 200 72
-------------------------------------------------------------------------------------------------------------------------
E5355 29/09/2015 C116 530 A 450 80
-------------------------------------------------------------------------------------------------------------------------
E5363 01/10/2015 C124 930 A 500 430
-------------------------------------------------------------------------------------------------------------------------
E5364 02/10/2015 C125 915 A 800 115
-------------------------------------------------------------------------------------------------------------------------
E5367 03/10/2015 C128 427 A 350 77
-------------------------------------------------------------------------------------------------------------------------
E5373 10/10/2015 C134 1023 A 550 473
-------------------------------------------------------------------------------------------------------------------------
The total outstanding is
£2062
總outstanding
通過找到outstanding
量的總和找到。未付金額爲finaltotal
減去amountpaid
。任何幫助將非常感激。
你有什麼問題? –
我想找到最後一列(未付金額)的總和並打印出來。它應該等於2062 – Seruza