怎样才能去掉数字10~12造成的压痕?

2024-09-30 08:25:59 发布

您现在位置:Python中文网/ 问答频道 /正文

如何去除由数字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]))

Tags: count数字itemplistdoubleprintdeliveryup
2条回答

您已经在使用string formatting;只需为第一项指定宽度。你知道吗

print("{0:3d}   ...".format(count + 1, ...))

应产生:

   1
   2
   3
 ...
  10

只需打印表格:

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)   

相关问题 更多 >

    热门问题