标签:解释 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. 输出效果
标签:解释 payment nbsp term rem div tty float mount
原文地址:https://www.cnblogs.com/AHappyBird/p/9340784.html