python_表格形式輸出

來源:互聯網
上載者:User

標籤:解釋   payment   nbsp   term   rem   div   tty   float   mount   

1. 安裝prettytable模組 pip install prettytable

在Pycharm中的解譯器中調用該模組的話,需要在該IDE環境下的terminal裡安裝,在外部運行py檔案的話需要另外再安裝一次,因為兩者的路徑不一致

from prettytable import Prettytable

2. 代碼執行個體 

def FinanceCalculator():    ‘輸入初始金額和月開銷數,返回剩下的金額、當月的支出數、和最後的支出數‘    print ‘Enter opening balance:‘,    RawBalance = float(raw_input())    Balance = RawBalance    print ‘Enter monthly payment:‘,    MonthlyPayment = float(raw_input())    print ‘\t\tAmount\tRemaining‘    table = PrettyTable([‘Pymt#‘,‘Paid‘,‘Balance‘])    table.add_row([‘---‘,‘---‘,‘---------‘])    i = 0    while Balance>0:        if i==0:            paid = 0.00        elif i>0 and Balance>=MonthlyPayment:            paid = MonthlyPayment        else:            paid = Balance        Balance = Balance-paid        table.add_row([i,‘$%.2f‘ % paid,‘$%.2f‘ % Balance])        i+=1    table.sort_key(i)    table.reversesort=False    table.border = 0    print table

3. 輸出效果

 

python_表格形式輸出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.