第一次写购物车,甚是简陋。
生活随笔
收集整理的這篇文章主要介紹了
第一次写购物车,甚是简陋。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# 買家 賣家 商品 金錢
#把貨物放在貨架上
li = [{'name': '蘋果', 'price': 10},{'name': '香蕉', 'price': 20},{'name': '西瓜', 'price': 30}
]
shopping_car = {}
print('歡迎光臨大鐵錘水果店~~')
money = input('讓我看看你的錢:')if money.isdigit() and int(money) > 0:while 1:for i,k in enumerate(li):print('序號{},商品{},價格{}'.format(i,k['name'],k['price']))choose = input('請輸入您要購買的商品序號:')if choose.isdigit() and 0 <= int(choose) <= len(li) :num = input('您要購買的商品數量:')if num.isdigit():if int(money) >= li[int(choose)]['price']*int(num):money = int(money) - li[int(choose)]['price']*int(num)if li[int(choose)]['name'] in shopping_car:shopping_car[li[int(choose)]['name']] = shopping_car[li[int(choose)]['name']] + int(num)else:shopping_car[li[int(choose)]['name']] = int(num)print('購物車中的商品有{},您的余額為{}'.format(shopping_car,money))else:print('窮鬼,回家要錢去!')breakelse:print('你是不是傻!數量是數字!')else:print('都說了是序號,你是不是傻!')
繼續學習更加復雜的編碼方式吧。
轉載于:https://www.cnblogs.com/NICE-man/p/10581041.html
總結
以上是生活随笔為你收集整理的第一次写购物车,甚是简陋。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言中的0UL或1UL是什么意思
- 下一篇: 数据仓库--基本概念