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

购物车小程序

时间:2018-05-09 01:19:32      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:end   number   cycle   UI   mac   余额   list   pre   pen   

salary = input("your salary =")
_salary = int(salary)
list = []
for i in range(10):
a = "1、iphone6s need 5800"
b = "2、mac book need 9000"
c = "3、coffee need 32"
d = "4、python book need 80"
f = "5、bicycle need 1500"
print(a)
print(b)
print(c)
print(d)
print(f)
_a = 5800
_b = 9000
_c = 32
_d = 80
_f = 1500
choose = input("The number you choose is:")
if choose.isdigit():
_choose =int(choose)
if _choose == 1:
if _salary - _a>0:
print("已加入 iphone6s 到你的购物车,当前余额:", _salary - _a)
_salary = _salary - _a
list.append("iphone6s 5800")
else:
print("余额不足:",(_salary - _a))
break
elif _choose == 2:
if _salary - _b>0:
print("已加入 mac book 到你的购物车,当前余额:", _salary - _b)
_salary = _salary - _b
list.append("mac book 9000")
else:
print("余额不足:",(_salary - _b))
break
elif _choose == 3:
if _salary - _c>0:
print("已加入 coffee 到你的购物车,当前余额:", _salary - _c)
_salary = _salary - _c
list.append("coffee 32")
else:
print("余额不足:",(_salary - _c))
break
elif _choose == 4:
if _salary - _d>0:
print("已加入 python book 到你的购物车,当前余额:", _salary - _d)
_salary = _salary - _d

list.append("python book 80")
else:
print("余额不足:",(_salary - _d))
break

elif _choose == 5:
if _salary - _f>0:
print("已加入 bicycle 到你的购物车,当前余额:", _salary - _f)
_salary = _salary - _f
list.append("bicycle 1500")
else:
print("余额不足:",(_salary - _f))
break
else:
if choose == ‘quit‘:
break
print("你已购买以下商品:")
print()
print(list)
print()
print("你的余额为:",_salary)
print()
print("欢迎下次光临")

购物车小程序

标签:end   number   cycle   UI   mac   余额   list   pre   pen   

原文地址:https://www.cnblogs.com/shenyueboy/p/9011695.html

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