-------- Final Receipt --------
Milk, 2 Litres $ 2
Potatoes $ 7.5
Sugar $ 3.5
我希望这份打印报表
-------- Final Receipt --------
Milk, 2 Litres $ 2
Potatoes $ 7.5
Sugar $ 3.5
这是我的印刷品
for mydata in zip(*list(product_in_basket.values())[:-1]):
print(mydata[1],'$',mydata[2])
产品列表中的产品是嵌套字典
代码是完全工作,但需要我的输出风格
您可能希望使用
ljust
用空格填充字符串。使每一列都有一定的宽度。你知道吗我做了
len(header)
来发现你的头是32个字符,所以现在每列占据了其中的一半(16个)。你知道吗见:How can I fill out a Python string with spaces?
结果:
您可以使用
ljust
:输出:
相关问题 更多 >
编程相关推荐