如何删除数字10~12之前的缩进直到第9个数字没有问题,因为数字没有缩进。
mList = [" Ganja Masta"," Chicken"," Supreme"," Hawaiian"," God Father"," Double Cheese"," Vegetarian"," Meat Lovers"," Beef and BBQ","Fire Breather","Mr Wedge","Double Bacon"]
pList = [8.50,8.50,8.50,8.50,8.50,8.50,8.50,13.50,13.50,13.50,13.50,13.50]
qList = [0,0,0,0,0,0,0,0,0,0,0,0,0]
tList = [0,0,0,0,0,0,0,0,0,0,0,0]
cList = ["Delivery","delivery","Pickup","pickup","PickUp","pick-up","Pick-up","Pick-Up"]
dList = ["Delivery","delivery"]
print("Code No Item Price Quantity Item Total")
print("=======================================================================")
for count in range(len(mList)):
print("{0} {1:<15} ${2:>5.2f} {3:>5} ${4:>5.2f}".format(count+1,mList[count],pList[count],qList[count],tList[count]))
答案 0 :(得分:3)
答案 1 :(得分:0)
只需打印一张表:
table=[
["Code No", "Item", "Price", "Quantity", "Item Total"],
[1,'Ganja Masta', 8.50, 0, 0.00],
[2,'Chicken', 8.50, 0, 0.00],
[3,'Supreme', 8.50, 0, 0.00],
[4,'Hawaiian', 8.50, 0, 0.00],
[5,'God Father', 8.50, 0, 0.00],
[6,'Double Cheese', 8.50, 0, 0.00],
[7,'Vegetarian', 8.50, 0, 0.00],
[8,'Meat Lovers', 13.50, 0, 0.00],
[9,'Beef and BBQ', 13.50, 0, 0.00],
[10,'Fire Breather', 13.50, 0, 0.00],
[11,'Mr Wedge', 13.50, 0, 0.00],
[12,'Double Bacon', 13.50, 0, 0.00]
]
def printTable (tbl, borderHorizontal = '-', borderVertical = '|', borderCross = '+'):
cols = [list(x) for x in zip(*tbl)]
lengths = [max(map(len, map(str, col))) for col in cols]
f = borderVertical + borderVertical.join(' {:>%d} ' % l for l in lengths) + borderVertical
s = borderCross + borderCross.join(borderHorizontal * (l+2) for l in lengths) + borderCross
print(s)
for row in tbl:
print(f.format(*row))
print(s)
printTable(table)