Commit 3fb1d31d by BellCodeEditor

auto save

parent 9ed85b40
Showing with 13 additions and 6 deletions
# 神奇百货中的物品已经帮你创建好啦,接下来要看你的了~ # 神奇百货中的物品已经帮你创建好啦,接下来要看你的了~
dict= {'可口可乐':3,'旺仔牛奶':4,'农夫山泉':1,'辣条':3,'巴西烤肉':2,'果冻':4,'乐事':5,'奥利奥':10,'巧克力':6} dict= {'可口可乐':3,'旺仔牛奶':4,'农夫山泉':1,'辣条':3,'巴西烤肉':2,'果冻':4,'乐事':5,'奥利奥':10,'巧克力':6}
j=input("你要买什么?") dict2= {'可口可乐':3,'旺仔牛奶':4,'农夫山泉':1,'辣条':3,'巴西烤肉':2,'果冻':4,'乐事':5,'奥利奥':10,'巧克力':6}
if j in dict: #dict2存放的是商品名和库存
prink('巧克力'(dict[j])) #1.询问买家要买什么商品input()
q = input("要买什么商品:")#因为在后续的代码中会使用到刚刚输入的内容
j = input("要买几件商品:")#input()函数的返回值是字符串类型
#2.如果有该商品,就输出该商品的价格
if q in dict and dict2[q] > int(j):#总价 = 单价(dict[q]) * 数量(j)转换为数字
print("亲,您购买的商品" + q + ",单价为:" + str(dict[q]) +'元;总价为:' + str(eval(j) * dict[q]) )
dict2[q] = dict2[q] - int(j)#库存更新
#3.如果没有则输出缺货
else: else:
prink() print("亲,您购买的商品缺货,换一个吧~")
\ No newline at end of file print(dict2)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment