iT邦幫忙

2024 iThome 鐵人賽

DAY 14
0

練習昨天學習到的list列表、set集合以及tuple元組

goods = []
prices = []
#無窮迴圈
while True:
    good = input("輸入想購買的物品:")
    if good.lower()=="done":
        break
        
    price = float(input("請輸入{good}的價格:")
    goods.append(good)
    prices.append(price)
    
print("商品",goods)
print("價格",prices)
for index,item in enumerate(goods):
    print(f"第{index+1}項商品是{goods},價格為:{prices[index]:.2f}")

total = sum(prices)
print(f"總價格是:${total}")


輸入想購買的物品:apple
請輸入 apple 的價格:20
輸入想購買的物品:water
請輸入 apple 的價格:30
輸入想購買的物品:done
第 1 項商品是 apple ,價格為:20.00
第 2 項商品是 water ,價格為:30.00
總價格是:$50.00

上一篇
Day 13: list, sets, tuple
下一篇
Day 15: 字典 Dictionary + 販賣機程式
系列文
30天零基礎學習Python程式語言21
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言