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个小时的苦果,哈哈哈,虽然很耗时间,但是能做出来真的肯开心。

相关推荐