python购物车

Posted hushuichang1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python购物车相关的知识,希望对你有一定的参考价值。

哈哈哈哈,怎么说呢,苦尽甘来吧,终于,购物车这个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," "
"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," "
"The rest of money is:",money)
break
else:
print("Sorry,your balance is insufficient")
print("you want buy is:",mmy," "
"The rest of money is:",money)
break
else:
print("Invalid input")
break

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

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

 

以上是关于python购物车的主要内容,如果未能解决你的问题,请参考以下文章

python 购物车代码

Python简单的购物车小代码

Python小代码_3_购物车

常用python日期日志获取内容循环的代码片段

python 有用的Python代码片段

Python 向 Postman 请求代码片段