DAY 20
0
Software Development

## [Day24]一起來做飲料點餐系統吧！

``````bonus=5 #全班總成績的bonus
from functools import reduce
bonus=3
return bonus+reduce(lambda x,y:x+y,A)

if __name__=='__main__':
w=[0.05,0.2,0.3,0.35,0.1]
print('Hank got {} marks in this course.'.format(bonus+accum(grade,w)))

#output:Hank got 88.45 marks in this course.
``````

# 如果想要製作一個簡易的飲料店點餐機呢？

1. 盡可能將程式分類並架構化，方便針對後續修改時比較友善
2. 使用dict來做找查，降低運算時間
3. 變數命名盡可能使用可讀性比較高的命名方法
4. 有除錯(輸入錯誤)的判斷及控制方法

``````import math

#------------Basic questions and identifications-----------
def set1():
tyPe={"a":"紅茶","b":"綠茶","c":"奶茶"}
size={"a":"中杯","b":"大杯"}
Babo={"a":"加珍珠","b":""}
sugar={"a":"全糖","b":"少糖","c":"無糖"}
ice={"a":"全冰","b":"半冰","c":"去冰"}
more={"a":True,"b":False}
return [tyPe,size,Babo,sugar,ice,more]

def problems():
Q0="請問你要什麼飲料：a:紅茶,b:綠茶,c:奶茶"
Q1="請問你要的大小是：a:中杯,b:大杯"
Q2="請問你要加珍珠嗎：a:加,b:不加"
Q3="請問你的甜度是：a:全糖,b:少糖,c:無糖"
Q4="請問你的冰塊是：a:全冰,b:半冰,c:少冰"
...
return[Q0,Q1,Q2,Q3,Q4,..]

#------------Main qusestion-----------
#------------Using k confirm program working-----------

k=True # 判斷要不要繼續問下去的參數
Set=set1()
question=problems()
current_order=[]

#------------What drink do you want?---------
for i in range(5):
print(question[i])
check=input()
if check in Set[i]:
current_order.append(Set[i][check])
else:#當輸入引述不在dict中時，回傳False
k=False

#------------How many do you need?---------
print(question[5])
check=input()
if check.isdigit(): #判斷是否為數字
current_order.append(int(check))
else:#當輸入引述不在dict中時，回傳False
k=False

#------------Would you want more?---------
print(question[6])
check=input()
if (check in Set[5]):
order_more=Set[5][check]#當要繼續點餐order_more=True，不點餐order_more=False
else:
order_more=False
k=False
return current_order,k,order_more #ask customers what he want

#------------Final question(bags, cups)------------

def recy(cup): #is the discount of the cup due to environment friendly
...

def bag(cup): #is the cost of the bag
...

#------------Caculate cost------------
def Price(drink,babo_check):
...

#------------Classification and statistics------------
def classification(drinklist):
#This is classification and statistics of various beverages.
cup,total_drink_price=0,0
collection={}

for i in range(len(drinklist)):
beverages_mainname=drinklist[i][0]+drinklist[i][1] # type of drink
icesur=drinklist[i][2]+drinklist[i][3]+drinklist[i][4] # ice and sugar

# caculating price just drink
total_drink_price+=Price(beverages_mainname,drinklist[i][2])*drinklist[i][5]
# caculating total cups
cup+=drinklist[i][5]

#classification and counting
if (beverages_mainname+icesur in collection):
collection[beverages_mainname+icesur]=collection[beverages_mainname+icesur]
+drinklist[i][5]
elif (not (beverages_mainname+icesur in collection)) and drinklist[i][5]!=0:
collection.setdefault(beverages_mainname+icesur,drinklist[i][5])
return collection,cup,total_drink_price

#------------This is main.------------
...

#------------Bags and discounts------------
...
``````