码迷,mamicode.com
首页 > 编程语言 > 详细

python购物车

时间:2020-02-09 16:23:17      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:lan   break   开心   ssi   pre   comm   不同   代码   lease   

哈哈哈哈,怎么说呢,苦尽甘来吧,终于,购物车这个B东西,终于让老子搞出来了

money=int(input("please put you money:"))
print("you money is",money)
commodity=[["iphone",9000],
["huawei",8000],
["redmi",3000],
["oppo",2000]]
print,enumerate(commodity)
mmy=[]
a=""
while True:
for i,k in enumerate(commodity):
print(i,k)
want_buy=int(input("please put you want buy:"))
if want_buy<=3:
if money>=commodity[want_buy][1]:
sur=money-commodity[want_buy][1]
mmy.append(commodity[want_buy])
money=sur
print("you want buy is:",mmy,"\t"
"The rest of money is:",sur)
a=input("Keep pressing‘y‘,Press ‘n‘ at the end:")
if a=="y":
continue
elif a=="n":
break
print("Sorry,your balance is insufficient")
print("you want buy is:",mmy,"\t"
"The rest of money is:",money)
break
else:
print("Sorry,your balance is insufficient")
print("you want buy is:",mmy,"\t"
"The rest of money is:",money)
break
else:
print("Invalid input")
break

这个是整个过程的代码,独一无二,这个和教程上是不同的,我也操作过,基本没什么问题,

3个小时的苦果,哈哈哈,虽然很耗时间,但是能做出来真的肯开心。

 

python购物车

标签:lan   break   开心   ssi   pre   comm   不同   代码   lease   

原文地址:https://www.cnblogs.com/hushuichang1/p/12287264.html

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