เครื่องคิดแคลอรี

📋 โจทย์

รับเมนูผลไม้ทีละตัว (1=Apple 100cal, 2=Papaya 120cal, 3=Banana 200cal, 4=Orange 60cal, 5=Exit) เมื่อรับ 5 แสดง "Bye Bye" บรรทัดแรก บรรทัดที่ 2 แสดง "Total Calories: X"

⚠️ ข้อจำกัด

แต่ละค่า 1-5, รับจนกว่าจะได้ 5

📝 ตัวอย่าง

ตัวอย่างที่ 1
Input:
3
1
5
Output:
Bye Bye
Total Calories: 300
ตัวอย่างที่ 2
Input:
5
Output:
Bye Bye
Total Calories: 0
ตัวอย่างที่ 3
Input:
1
2
3
4
5
Output:
Bye Bye
Total Calories: 480
🔓 ดูเฉลย
cal = {1: 100, 2: 120, 3: 200, 4: 60}
total = 0
while True:
    c = int(input())
    if c == 5:
        break
    total += cal.get(c, 0)
print("Bye Bye")
print(f"Total Calories: {total}")

💡 ใช้ while True + break เมื่อรับ 5 เก็บแคลอรีใน dict แล้วสะสมด้วย += ทุกรอบ

🐍 main.py

กด Run เพื่อรันโค้ด หรือ ตรวจคำตอบ เพื่อตรวจ test cases