举 2020-02-09
哈哈哈哈,怎么说呢,苦尽甘来吧,终于,购物车这个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个小时的苦果,哈哈哈,虽然很耗时间,但是能做出来真的肯开心。
而且为了用户体验更好,在滑动界面时,这个图标要乖乖地藏起来,不能影响用户操作。我仔细分析了一下,哟,这不就是中午点外卖时用的饿了么上面的购物车按钮么?到了这一步,相信大家都会想到是用触摸事件来实现了。