【发布时间】:2014-11-29 02:49:07
【问题描述】:
我必须创建一个程序,要求用户输入要购买的商品数量。然后程序要求用户输入每个项目的项目和价格,给出一个总数并提供找零的数量。
我被困在需要合并列表并以货币格式输出项目和成本的部分
#Checkout program
print "Welcome to the checkout counter! How many items will you be purchasing?"
number = int (raw_input ())
grocerylist = []
costs = []
for i in range(number):
groceryitem = raw_input ("Please enter the name of product %s:" % (i+1))
grocerylist.append(groceryitem)
itemcost = float(raw_input ("What is the cost of %s ?" % groceryitem))
costs.append(itemcost)
order = {}
for index in range (min(len(grocerylist), len(costs))):
order[grocerylist[index]] = costs[index]
print ("This is your purchase") + str(order)
【问题讨论】:
标签: python