首页 > 其他 > 详细

购物车作业

时间:2017-09-28 15:07:09      阅读:256      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/evn python
# -*- coding:utf-8 -*-
# Author: Aron
import sys
commodity = ‘‘‘
1.苹果 200
2.橘子 350
3.香蕉 500
4.水蜜桃 750
5.罗明 2000
‘‘‘
ShoppingCart = []
wages = int(input("你的工资:"))
while True:
print(commodity)
s1 = input("想购买的商品序号:")
if s1 == ‘1‘:
ShoppingCart.append([‘苹果‘,‘200‘])
continue
elif s1 == ‘2‘:
ShoppingCart.append([‘橘子‘,‘350‘])
continue
elif s1 == ‘3‘:
ShoppingCart.append([‘香蕉‘,‘500‘])
continue
elif s1 == ‘4‘:
ShoppingCart.append([‘水蜜桃‘,‘750‘])
continue
elif s1 == ‘5‘:
ShoppingCart.append([‘罗明‘,‘2000‘])
continue
elif s1 == ‘Q‘:
commodity1 = []
for i in list(ShoppingCart):
for i1 in list(i[::2]):
commodity1.append(i1)
for n in list(ShoppingCart):
for n1 in list(n[1:2]):
n1 = int(n1)
wages = wages - n1
for n in list(ShoppingCart):
for n1 in list(n[1:2]):
n1 = int(n1)
wages = wages - n1
if wages < 0:
wages = input("你的余额已经不足,请重新选购。请重新输入工资:")
ShoppingCart = [ ]
continue
else:
print("你够买的商品为:",list(commodity1))
print("你的余额为:%s" % wages)
sys.exit()
else:
print("输入错误,请重新输入:")
continue

购物车作业

原文:http://www.cnblogs.com/huangbipeng/p/7606721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!