我正在尝试获取预制的dict,将一些用户输入保存到列表中,然后打印出用户输入的内容。虽然我知道如何做这部分,但我想格式化保存的用户输入并更改他们的字典周围的名字这是我的代码
print("Hi There! Welcome to sSpecialists!")
print("To start shopping, note down what you want to buy and how much of it")
print("Here are the purchasable items")
print("~~~~~")
print("12345670 is a hammer (£4.50)")
print("87654325 is a screw driver (£4.20)")
print("96385272 is a pack of 5 iron screws (£1.20)")
print("74185290 is pack of 20 100mm bolts (£1.99)")
print("85296374 is a pack of 6 walkers crisps (£1)")
print("85274198 is haribo pack (£1)")
print("78945616 is milk (£0.88)")
print("13246570 is a bottle of evian water (£0.99)")
print("31264570 is kitkat original (£0.50)")
print("91537843 is a cadbury bar (£1)")
print("~~~~~")
items = {'12345670' : {'name' : 'hammer', 'price' : 4.50},
'87654325' : {'name' : 'screwDriver', 'price' : 4.20},
'96385272' : {'name' : 'packOf5IronnScrews', 'price' : 1.20},
'74185290' : {'name' : 'packOf200mmBolts', 'price' : 1.99},
'85296374' : {'name' : 'packOf6WalkersCrisps', 'price' : 1},
'85274198' : {'name' : 'hariboPack', 'price' : 1},
'78945616' : {'name' : 'milk', 'price' : 0.88},
'13246570' : {'name' : 'bottleOfEvianWater', 'price' : 0.99},
'31264570' : {'name' : 'kitkatOriginal', 'price' : 0.50},
'91537843' : {'name' : 'cadburyBar', 'price' : 1}}
print("Alright, now start typing what you want to order")
print(" ")
price = 0
full_list = " "
chos_items = []
while full_list != "":
print(" ")
full_list = input("Type: ")
if full_list == 'end':
break
item = int(full_list)
amount = int(input("Amount: "))
item = int(full_list)
if full_list in items:
orders = print("{} {:>5} (£{:0.2f})".format(full_list, items[full_list]['name'], items[full_list]['price']))
if orders != "":
chos_items.append(full_list)
price = int(amount) * (items[full_list]['price']) + price
print("Subtotal is currently at "+str(price))
print("Your subtotal is: " +str(price))
receipt = input("Would you like to view your receipt?: ")
if receipt == 'yes':
for item in items:
print(print("{} {:>5} (£{:0.2f})".format(chos_items, items[chos_items]['name'], items[chos_items]['price'])))