購物車作業
阿新 • • 發佈:2017-09-28
ron list art 輸入 作業 [] utf-8 pen 不足
#!/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
購物車作業