作业1

goods_list = [
{'name':'iphone','price':4500,'count':40},
{'name':'电脑','price':7000,'count':100},
{'name':'平板','price':5000,'count':60},
{'name':'羽绒服','price':500,'count':80},
{'name':'西服','price':1000,'count':90},
{'name':'运动鞋','price':200,'count':120},
{'name':'vivo','price':2000,'count':200},
{'name':'自行车','price':2100,'count':300}]

shopping_list = []
info = """----- supermarket info -----
1.Please enter the goods number you want to buy
2.input quit to quit
3.input check to check your shop cart
4.input good to see goods
"""
print(info)

while True:
money = input("please input your money:")
if money.isdigit():
if int(money) >= 0:
money = int(money)
break
else:
print("input money is wrong!")
continue


def good():
for i, item in enumerate(producty_list):
print(i, item)


good()

while True:

buy = input("input the good number ,or quit or check:")
if buy == 'quit':
print("good bye")
break
if buy == 'good':
good()
continue
elif buy == 'check':
print("Shop cart has", shopping_list)
continue

if buy.isdigit():
buy = int(buy)
if buy in range(len(producty_list)):
if money >= producty_list[buy][1]:
producty_name = producty_list[buy][0]
money -= producty_list[buy][1]
shopping_list.append(producty_list[buy][0])
print("{0} has added to your shoppong cart,you have {1} yuan left.".format(producty_name, money))

else:
print("you don't have enough money!")
else:
print("There's no goods you want here")
else:
print("I cant understand what you want to buy.....")

 

转载于:https://www.cnblogs.com/rj112233/p/10903020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值