shop_car = []#用來存放購買的商品
goods = {
1:['麥香紅茶(鋁箔包裝一瓶300CC)',10],
2:['麥香紅茶(鋁箔包裝一箱300CC*24)',200],
3:['謎之白粉 每公克',9527],
4:['MSI Modern 15 A11MU-1028TW',17900],
5:['捷安特 TRANCE X 29 1',108000],
6:['2023 Rolls-Royce Ghost ',22036000]
}#商品列表
while True:
salary = input("歡迎光臨謎之商店,您有多少預算?") # 輸入有多少錢
if salary.isdigit(): # 判斷是否為整數
salary = int(salary) # 將字元串轉化為整數
print("您是否要想買東西?")
flag1 = input("Y N:")
if flag1.upper() == 'N': # 將字元串大寫
exit("歡迎下次光臨") # 退出程式並輸出“歡迎下次光臨”
elif flag1.upper() == 'Y':
break # 終止迴圈
elif flag1.upper() == 'Q':
exit("歡迎下次光臨")
elif salary.upper() == 'Q':
exit("歡迎下次光臨")
while True:
print("謎之商城".center(30,'-')) # 輸出以-----淘寶------
for i in goods: # 迴圈輸出
print(i,goods[i])
print("謎之商城".center(30, '-'))
choice_good = input("請輸入商品編碼:")#接受一個字元串
if choice_good.isdigit() :
choice_good = int(choice_good)
if choice_good >= 1 and choice_good <= 6:
if salary >= goods[choice_good][1]:
shop_car.append(goods[choice_good][0]) # 給字典中添加元素
salary = salary - goods[choice_good][1]
print("您購買的商品為:", goods[choice_good][0])
print("餘額為:", salary)
print("是否繼續:")
contin = input("Y N")
if contin.upper() == 'N':
break
elif contin.upper() == 'Q':
break
else:
print('餘額不足')
print("是否還要再購買其他物品?")
contin = input("Y N")
if contin.upper() == 'N':
break
elif contin.upper() == 'Q':
break
else :
print("沒有這個編號!")
continue # 暫停本次迴圈
elif choice_good.upper() == "Q" :
break
else:
print("對不起,我看不懂您想要哪一個商品。。。")
print("你買了:",end =' ')
for i in shop_car:
print(i,end=' ')
print()
print("餘額為:",salary)
print(
"歡迎下次再度光臨~~")