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,"\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个小时的苦果,哈哈哈,虽然很耗时间,但是能做出来真的肯开心。
相关推荐
87281248 2020-07-04
yourFriend 2020-06-09
THEEYE 2020-05-27
taiyanghua 2020-02-14
zhangwentaohh 2020-01-25
87261046 2019-12-23
yaoliuwei 2013-05-15
程序员俱乐部 2019-12-12
lbPro0 2019-12-12
csdnwpno 2017-08-10
那些年写过的代码 2015-06-17
ShaLiWa 2019-06-28
LeavesYu 2019-06-28
oZaoHua 2019-06-28
iamrunner 2017-03-18