From fb9549b85517db9dfee0d2a75ad0bbbf27bd9a5f Mon Sep 17 00:00:00 2001 From: YXYaaaa <16270691+yxyaaaa@user.noreply.gitee.com> Date: Sat, 8 Aug 2026 18:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shopping.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 shopping.py diff --git a/shopping.py b/shopping.py new file mode 100644 index 0000000..64a6160 --- /dev/null +++ b/shopping.py @@ -0,0 +1,32 @@ +money=200 +products=[ +{"name":"苹果","price":3}, +{"name":"香蕉","price":3}, +{"name":"可乐","price":3}, +{"name":"水","price":3}, +{"name":"酸奶","price":5}, +{"name":"手机","price":200}, +{"name":"电脑","price":300} +] +cart=[] +aa=True +while aa: + a=input("请输入您要购买的商品,按Q退出") + if a == "Q": + aa=False + break + fond=None + for p in products: + if a==p["name"]: + fond=p + break + if fond is None: + print('商品不存在') + elif money>=fond["price"]: + cart.append(fond["name"]) + money-=fond["price"] + else: + print("余额不足") + aa=False + +print(cart) -- Gitee