码迷,mamicode.com
首页 > 其他好文 > 详细

购物车作业

时间:2017-09-28 15:09:53      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:continue   coding   购物   cart   input   工资   imp   []   lis   

#!/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

购物车作业

标签:continue   coding   购物   cart   input   工资   imp   []   lis   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!