本文實(shí)例為大家分享了python3實(shí)現(xiàn)點(diǎn)餐系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
目前成都創(chuàng)新互聯(lián)公司已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、子洲網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。題目:
某餐廳外賣每天更新菜品,但是搭配價(jià)格是不變的,具體如下:
"今天菜單如下","1 宮保雞丁","2 青椒雞米粒" ,"3 白蘿卜燜肉", "4 蒜薹臘肉", "5 豆腐包肉 ",
"6 鯉魚躍龍門", "7 涼拌蓮藕", "8 紅燒南瓜", "9 大白菜", "10 青菜", "11 荷包蛋(另加2元)", "12 蛋炒飯(10元)"
一葷一素10,兩素菜9元,一葷兩素11,,三素菜10,兩葷菜12,兩葷一素13,兩葷兩素14,兩葷三素15元
現(xiàn)在需要求取用戶輸入選擇菜品的編號(hào),求取需要支付的價(jià)格
代碼:
#coding UTF-8 # version = version_1_2 today_menu = ["今天菜單如下","1 宮保雞丁","2 青椒雞米粒" ,"3 白蘿卜燜肉", "4 蒜薹臘肉", "5 豆腐包肉 ", "6 鯉魚躍龍門", "7 涼拌蓮藕", "8 紅燒南瓜", "9 大白菜", "10 青菜", "11 荷包蛋(另加2元)", "12 蛋炒飯(10元)"] price =[0,0,12,0,0 ,10 ,13,0,9,11,14,0,10,0,15,0] def getTodayMenu(): return today_menu def showTodayMenu(interable): for today_menu_details in today_menu : print(today_menu_details) def showCombineNote(): print("提示:一葷一素10,兩素菜9元,一葷兩素11,,三素菜10,兩葷菜12,兩葷一素13,兩葷兩素14,兩葷三素15元") print("請(qǐng)輸入您點(diǎn)餐的編號(hào),編號(hào)之間用逗號(hào)分開,不同份數(shù)之間用空格隔開\n例如輸入1,9,10 2,6,8 3,10,謝謝 : ") def dealWithUserInput(): user_choise = input() user_choise_list = user_choise.split() price_total = 0#用price_total來記錄所點(diǎn)菜的總和 price_one = 0#用來計(jì)算每一份菜的價(jià)格 choosed_list = [] pay_total = 0 #用來保存優(yōu)惠后需要支付的價(jià)格 for one_order in user_choise_list : count_i = count_j =0 #count_i用來保存素菜的個(gè)數(shù) count_j用來保存混菜的個(gè)數(shù) hebaodan = 0#用來記錄荷包蛋的個(gè)數(shù) danchaofan = 0#用來記錄蛋炒飯的個(gè)數(shù) one_order_list = one_order.split(",")#one_order_list 保存的是["1","9","10] for menu_item in one_order_list :#menu_item 就是保存的單個(gè)的數(shù)字 #首先得防止用戶輸入的不是數(shù)字,是數(shù)字則處理,不是則提示用戶重新輸入 if menu_item.strip().isdigit(): #這里防止用戶輸入的時(shí)候跟預(yù)期的不一樣,可能多了一些空格,所以需要去掉空格后轉(zhuǎn)化為數(shù)字 if int(menu_item.strip()) <7: count_j += 1 elif int(menu_item.strip()) <11: count_i += 1 elif int(menu_item.strip()) == 11: hebaodan += 1 elif int(menu_item.strip()) == 12: danchaofan += 1 choosed_list.append(int(menu_item)) else: print("您輸入的有非數(shù)字類型,請(qǐng)重新運(yùn)行程序,謝謝") exit() choosed_list.append(0) #如果是正確的組合,則price[count_i*4 + count_j]是不會(huì)為0的,但是輸入一個(gè)數(shù)字代表特色菜品的時(shí)候也是可行的 #兩種組合都不是的時(shí)候就證明不是正確的組合,程序退出 if price[count_i*4 + count_j] ==0 and "12" not in one_order: print("您輸入的不是一個(gè)正確的組合,請(qǐng)重新運(yùn)行程序, 謝謝") exit() else: price_one= price[count_i*4 + count_j] + hebaodan *2 + danchaofan * 10 price_total += price_one #根據(jù)計(jì)算得到的總需要支付的價(jià)格,判斷享受哪種優(yōu)惠,得出優(yōu)惠后的價(jià)格 if price_total >=30: pay_total = price_total - 4 elif price_total >=26: pay_total = price_total - 3 elif price_total >=20: pay_total = price_total - 2 else: pay_total = price_total print("您預(yù)訂了 %d 份美食,具體如下: " % len(user_choise_list)) for choosed_item in choosed_list : if choosed_item == 0: print() else: print(today_menu[choosed_item]) print("您共需要支付 %d 元,謝謝" % pay_total) print("歡迎進(jìn)入點(diǎn)餐系統(tǒng)") today_menu = getTodayMenu() showTodayMenu(today_menu) showCombineNote() dealWithUserInput()