如何在一列中打印這些功能。如何在列中打印列表?
item = stock.stock_list(location_name)
for x in sorted(item):
"""Stock list of given location"""
print (x)
for y in sorted(item):
"""Stock price of give location and stock list"""
print ("{0:.2f}".format(stock.stock_price(y)))
for z in sorted(item):
"""stock qty of given location name and item"""
print(stock.stock_quantity(location_name, z))
輸出是
Elephant foot yam
Kai-lan
16.25
13.96
90
18
希望它是
Elephant foot yam 16.25 90
Kai-lan 13.96 18
第一個必須被左對齊和20寬,所述第二被右對齊和8寬和第三右對齊,6寬。
也是另外一個問題。
如何從括號內的下方打印location_id?
print(toptext, location_name, location_id)
輸出是
Stock summary for location 123456789
我希望它是
Stock summary for Wellington (123456789)
我累
print(toptext, location_name, "(", location_id ,")")
但像這樣的括號之間的空間(123456789)
預先感謝您
在問題的第二部分,您的目標是在那裏沒有「位置」,而是「惠靈頓」嗎?那麼它是一個錯誤,位置不是由實際位置取代?如果是這樣,您需要深入瞭解location_name的設置方式。 – syntonym 2015-03-25 10:10:32