Python学习笔记016

购物车

 

# __author:XY
# date: 2020/3/4

product=[
('Macbook',9000),
('iphone',5000),
('ipad',3500),
('mini',2000),
('ipod',1500),
('airpods',1000),
('apple pencil', 700),
('shuffle',500),
('earpods',200),
]
salary=input('Please input your salary:')
cart=[]
msg_wrong='Wong input! Please input the correct number or letter!'

if salary.isdigit():
salary=int(salary)
while True:
print('----Shopping Menu------')
for i, p in enumerate(product,1):
print(i,p)
print('----Welcome------')
print('Please input the Number(q=quit):')
choice=input('>>>:')
if choice.isdigit():
choice=int(choice)
if 0<choice<=len(product):
item=product[choice-1]
if salary<item[1]:
print('Not enough money!')
else:
salary-=item[1]
cart.append(item)
print(item,'is in your shopping cart! you have %s yuan left'%salary)
else:
print(msg_wrong)
elif choice=='q':
print('Here are the items you have purchased!')
for x in cart:
print(x)
print('Your have %s yuan left'%salary)
print('bye-bye')
break
else:
print(msg_wrong)
else:
print(msg_wrong)
posted @ 2020-03-04 14:54  wtzxxy  阅读(139)  评论(0编辑  收藏  举报