phtyon 寫超市 結賬

yytkkp發表於2020-11-21

flag = ‘ok’
lists = []
goods_lists = [[‘水果’,[[‘鴨梨’,18],[‘桃子’,30],[‘蘋果’,21],[‘榴蓮’,5],[‘香蕉’,3]]],[‘蔬菜’,[[‘胡蘿蔔’,11],[‘香菜’,21],[‘圓白菜’,3],[‘土豆’,2],[‘地瓜’,4]]]]
while True:
if flag==‘no’:
total_price = 0
print(‘商品名稱 單價 購買數量 購買總價’)
for a, b, c, d in lists:
print(’ ’ + a, ’ ’ * 3 + str(b), ’ ’ * 3 + str( c), ’ ’ * 3 + str(d))
total_price += d
print(‘總價格為’ + str(total_price))
break
n = 1
print(‘歡迎光臨 XXX超市’)
print(’################################’)
for a,b in goods_lists:
print(’ ‘+str(n)+’ ‘+a)
n = n+1
print(’################################’)
num1 = int(input(‘請選擇分類序號:’)) - 1
while True:
m = 1
print(‘歡迎光臨 XXX超市’)
print(’################################’)
for goods in goods_lists[num1][1]:
print(’ ‘+str(m)+’ ‘+goods[0]+’ ‘+str(goods[1])+‘元’)
m = m + 1
print(’################################’)
num2 = int(input(‘請選擇商品序號:’))-1
if num2==-1:
break
if num2==-2:
flag = ‘no’
break
n_lists = []
num3 = int(input(‘請選擇購買數量(輸入0返回上級選單,輸入-1結算退出)’))
n_lists.append(goods_lists[num1][1][num2][0])
n_lists.append(goods_lists[num1][1][num2][1])
n_lists.append(num3)
n_lists.append(goods_lists[num1][1][num2][1]*num3)
lists.append(n_lists)

相關文章