Asset_all = eval (input ("Please input total assets :"))
Car_dict = {}
# Dict_list = {
# "Computer": {"single_price": "unit price", "num": "count "}
#
#}
Goods = [
{"Name": "computer", "price": 1999 },
{"Name": "Mouse", "price": 10 },
{"Name": "yacht", "price": 20 },
{"Name": "beauty", "price": 998 },
]
For I in goods:
Print (I ['name'], I ['price'])
While true:
I2 = input ("Enter the product (y/y settlement ):")
If i2.lower () = 'y ':
Break
For item in goods:
If item ['name'] = I2:
Name = item ['name']
If name in car_dict.keys ():
Car_dict [name] ["num"] + = 1
Else:
Car_dict [name] = {"single_price": item ["price"], "num": 1}
Print (car_dict)
Sum_all = 0
For K, V in car_dict.items ():
Print (K, V)
N = V ['single _ price']
M = V ['num']
Sum_all + = m * n
Print (sum_all)
If asset_all <sum_all:
Print ("insufficient balance ")
Else:
Print ("purchased successfully ")
13 Shopping Cart 2 (use a dictionary)