def calculate_bmr(weight, height, age, gender):
"""คำนวณค่า BMR"""
if gender == "male":
bmr = 88.362 + (13.397 * weight) + (4.799 * height * 100) - (5.677 * age)
elif gender == "female":
bmr = 447.593 + (9.247 * weight) + (3.098 * height * 100) - (4.330 * age)
else:
return None
return bmr
def calculate_tdee(bmr, activity_level):
"""คำนวณค่า TDEE"""
activity_multipliers = {
"sedentary": 1.2,
"lightly active": 1.375,
"moderately active": 1.55,
"very active": 1.725,
"extra active": 1.9
}
return bmr * activity_multipliers.get(activity_level, 0) if bmr else None
def calculate_bmi(weight, height):
"""คำนวณค่า BMI"""
bmi = weight / (height ** 2)
if bmi < 18.5:
category = "Underweight"
elif 18.5 <= bmi < 24.9:
category = "Normal weight"
elif 25 <= bmi < 29.9:
category = "Overweight"
else:
category = "Obese"
return bmi, category
def calculate_calories_burned(activity, weight, duration):
"""คำนวณพลังงานที่เผาผลาญจากการออกกำลังกาย"""
met_values = {
"walking": 3.8,
"running": 7.5,
"cycling": 6.8,
"swimming": 8.0,
"yoga": 3.0
}
met = met_values.get(activity, 0)
calories_burned = (met * weight * duration) / 60 if met else None
return calories_burned
def main():
while True:
print("\nโปรแกรมคำนวณสุขภาพ")
print("1. คำนวณ BMI")
print("2. คำนวณ BMR และ TDEE")
print("3. คำนวณพลังงานที่เผาผลาญจากการออกกำลังกาย")
print("4. ออกจากโปรแกรม")
choice = input("กรุณาเลือกเมนู: ")
if choice == '1':
weight = float(input("กรุณาใส่น้ำหนัก (กก.): "))
height = float(input("กรุณาใส่ส่วนสูง (เมตร): "))
bmi, category = calculate_bmi(weight, height)
print(f"ค่า BMI ของคุณคือ: {bmi:.2f}")
print(f"หมวดหมู่: {category}")
elif choice == '2':
weight = float(input("กรุณาใส่น้ำหนัก (กก.): "))
height = float(input("กรุณาใส่ส่วนสูง (เมตร): "))
age = int(input("กรุณาใส่อายุ (ปี): "))
gender = input("กรุณาใส่เพศ (male/female): ").lower()
bmr = calculate_bmr(weight, height, age, gender)
if bmr is None:
print("ข้อผิดพลาด: เพศไม่ถูกต้อง")
continue
print(f"ค่า BMR ของคุณคือ: {bmr:.2f} กิโลแคลอรี")
print("ระดับกิจกรรม: sedentary, lightly active, moderately active, very active, extra active")
activity_level = input("กรุณาใส่ระดับกิจกรรมของคุณ: ").lower()
tdee = calculate_tdee(bmr, activity_level)
if tdee:
print(f"ค่า TDEE ของคุณคือ: {tdee:.2f} กิโลแคลอรีต่อวัน")
else:
print("ข้อผิดพลาด: ระดับกิจกรรมไม่ถูกต้อง")
elif choice == '3':
weight = float(input("กรุณาใส่น้ำหนัก (กก.): "))
print("กิจกรรมที่รองรับ: walking, running, cycling, swimming, yoga")
activity = input("กรุณาเลือกกิจกรรม: ").lower()
duration = float(input("กรุณาใส่ระยะเวลาออกกำลังกาย (นาที): "))
calories_burned = calculate_calories_burned(activity, weight, duration)
if calories_burned:
print(f"คุณเผาผลาญพลังงานไป {calories_burned:.2f} กิโลแคลอรี")
else:
print("ข้อผิดพลาด: กิจกรรมไม่รองรับ")
... (11 บรรทัด)
ZGVmIGNhbGN1bGF0ZV9ibXIod2VpZ2h0LCBoZWlnaHQsIGFnZSwgZ2VuZGVyKToKICAgICIiIuC4hOC4s+C4meC4p+C4k+C4hOC5iOC4siBCTVIiIiIKICAgIGlmIGdlbmRlciA9PSAibWFsZSI6CiAgICAgICAgYm1yID0gODguMzYyICsgKDEzLjM5NyAqIHdlaWdodCkgKyAoNC43OTkgKiBoZWlnaHQgKiAxMDApIC0gKDUuNjc3ICogYWdlKQogICAgZWxpZiBnZW5kZXIgPT0gImZlbWFsZSI6CiAgICAgICAgYm1yID0gNDQ3LjU5MyArICg5LjI0NyAqIHdlaWdodCkgKyAoMy4wOTggKiBoZWlnaHQgKiAxMDApIC0gKDQuMzMwICogYWdlKQogICAgZWxzZToKICAgICAgICByZXR1cm4gTm9uZQogICAgcmV0dXJuIGJtcgoKCmRlZiBjYWxjdWxhdGVfdGRlZShibXIsIGFjdGl2aXR5X2xldmVsKToKICAgICIiIuC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x1ZXMgPSB7CiAgICAgICAgIndhbGtpbmciOiAzLjgsCiAgICAgICAgInJ1bm5pbmciOiA3LjUsCiAgICAgICAgImN5Y2xpbmciOiA2LjgsCiAgICAgICAgInN3aW1taW5nIjogOC4wLAogICAgICAgICJ5b2dhIjogMy4wCiAgICB9CiAgICBtZXQgPSBtZXRfdmFsdWVzLmdldChhY3Rpdml0eSwgMCkKICAgIGNhbG9yaWVzX2J1cm5lZCA9IChtZXQgKiB3ZWlnaHQgKiBkdXJhdGlvbikgLyA2MCBpZiBtZXQgZWxzZSBOb25lCiAgICByZXR1cm4gY2Fsb3JpZXNfYnVybmVkCgoKZGVmIG1haW4oKToKICAgIHdoaWxlIFRydWU6CiAgICAgICAgcHJpbnQoIlxu4LmC4Lib4Lij4LmB4LiB4Lij4Lih4LiE4Liz4LiZ4Lin4LiT4Liq4Li44LiC4Lig4Liy4LieIikKICAgICAgICBwcmludCgiMS4g4LiE4Liz4LiZ4Lin4LiTIEJNSSIpCiAgICAgICAgcHJpbnQoIjIuIOC4hOC4s+C4meC4p+C4kyBCTVIg4LmB4Lil4LiwIFRERUUiKQogICAgICAgIHByaW50KCIzLiDguITguLPguJnguKfguJPguJ7guKXguLHguIfguIfguLLguJnguJfguLXguYjguYDguJzguLLguJzguKXguLLguI3guIjguLLguIHguIHguLLguKPguK3guK3guIHguIHguLPguKXguLHguIfguIHguLLguKIiKQogICAgICAgIHByaW50KCI0LiDguK3guK3guIHguIjguLLguIHguYLguJvguKPguYHguIHguKPguKEiKQogICAgICAgIGNob2ljZSA9IGlucHV0KCLguIHguKPguLjguJPguLLguYDguKXguLfguK3guIHguYDguKHguJnguLk6ICIpCiAgICAgICAgCiAgICAgICAgaWYgY2hvaWNlID09ICcxJzoKICAgICAgICAgICAgd2VpZ2h0ID0gZmxvYXQoaW5wdXQoIuC4geC4o+C4uOC4k+C4suC5g+C4quC5iOC4meC5ieC4s+C4q+C4meC4seC4gSAo4LiB4LiBLik6ICIpKQogICAgICAgICAgICBoZWlnaHQgPSBmbG9hdChpbnB1dCgi4LiB4Lij4Li44LiT4Liy4LmD4Liq4LmI4Liq4LmI4Lin4LiZ4Liq4Li54LiHICjguYDguKHguJXguKMpOiAiKSkKICAgICAgICAgICAgYm1pLCBjYXRlZ29yeSA9IGNhbGN1bGF0ZV9ibWkod2VpZ2h0LCBoZWlnaHQpCiAgICAgICAgICAgIHByaW50KGYi4LiE4LmI4LiyIEJNSSDguILguK3guIfguITguLjguJPguITguLfguK06IHtibWk6LjJmfSIpCiAgICAgICAgICAgIHByaW50KGYi4Lir4Lih4Lin4LiU4Lir4Lih4Li54LmIOiB7Y2F0ZWdvcnl9IikKICAgICAgICAKICAgICAgICBlbGlmIGNob2ljZSA9PSAnMic6CiAgICAgICAgICAgIHdlaWdodCA9IGZsb2F0KGlucHV0KCLguIHguKPguLjguJPguLLguYPguKrguYjguJnguYnguLPguKvguJnguLHguIEgKOC4geC4gS4pOiAiKSkKICAgICAgICAgICAgaGVpZ2h0ID0gZmxvYXQoaW5wdXQoIuC4geC4o+C4uOC4k+C4suC5g+C4quC5iOC4quC5iOC4p+C4meC4quC4ueC4hyAo4LmA4Lih4LiV4LijKTogIikpCiAgICAgICAgICAgIGFnZSA9IGludChpbnB1dCgi4LiB4Lij4Li44LiT4Liy4LmD4Liq4LmI4Lit4Liy4Lii4Li4ICjguJvguLUpOiAiKSkKICAgICAgICAgICAgZ2VuZGVyID0gaW5wdXQoIuC4geC4o+C4uOC4k+C4suC5g+C4quC5iOC5gOC4nuC4qCAobWFsZS9mZW1hbGUpOiAiKS5sb3dlcigpCiAgICAgICAgICAgIAogICAgICAgICAgICBibXIgPSBjYWxjdWxhdGVfYm1yKHdlaWdodCwgaGVpZ2h0LCBhZ2UsIGdlbmRlcikKICAgICAgICAgICAgaWYgYm1yIGlzIE5vbmU6CiAgICAgICAgICAgICAgICBwcmludCgi4LiC4LmJ4Lit4Lic4Li04LiU4Lie4Lil4Liy4LiUOiDguYDguJ7guKjguYTguKHguYjguJbguLnguIHguJXguYnguK3guIciKQogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgCiAgICAgICAgICAgIHByaW50KGYi4LiE4LmI4LiyIEJNUiDguILguK3guIfguITguLjguJPguITguLfguK06IHtibXI6LjJmfSDguIHguLTguYLguKXguYHguITguKXguK3guKPguLUiKQogICAgICAgICAgICAKICAgICAgICAgICAgcHJpbnQoIuC4o+C4sOC4lOC4seC4muC4geC4tOC4iOC4geC4o+C4o+C4oTogc2VkZW50YXJ5LCBsaWdodGx5IGFjdGl2ZSwgbW9kZXJhdGVseSBhY3RpdmUsIHZlcnkgYWN0aXZlLCBleHRyYSBhY3RpdmUiKQogICAgICAgICAgICBhY3Rpdml0eV9sZXZlbCA9IGlucHV0KCLguIHguKPguLjguJPguLLguYPguKrguYjguKPguLDguJTguLHguJrguIHguLTguIjguIHguKPguKPguKHguILguK3guIfguITguLjguJM6ICIpLmxvd2VyKCkKICAgICAgICAgICAgCiAgICAgICAgICAgIHRkZWUgPSBjYWxjdWxhdGVfdGRlZShibXIsIGFjdGl2aXR5X2xldmVsKQogICAgICAgICAgICBpZiB0ZGVlOgogICAgICAgICAgICAgICAgcHJpbnQoZiLguITguYjguLIgVERFRSDguILguK3guIfguITguLjguJPguITguLfguK06IHt0ZGVlOi4yZn0g4LiB4Li04LmC4Lil4LmB4LiE4Lil4Lit4Lij4Li14LiV4LmI4Lit4Lin4Lix4LiZIikKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIHByaW50KCLguILguYnguK3guJzguLTguJTguJ7guKXguLLguJQ6IOC4o+C4sOC4lOC4seC4muC4geC4tOC4iOC4geC4o+C4o+C4oeC5hOC4oeC5iOC4luC4ueC4geC4leC5ieC4reC4hyIpCiAgICAgICAgCiAgICAgICAgZWxpZiBjaG9pY2UgPT0gJzMnOgogICAgICAgICAgICB3ZWlnaHQgPSBmbG9hdChpbnB1dCgi4LiB4Lij4Li44LiT4Liy4LmD4Liq4LmI4LiZ4LmJ4Liz4Lir4LiZ4Lix4LiBICjguIHguIEuKTogIikpCiAgICAgICAgICAgIHByaW50KCLguIHguLTguIjguIHguKPguKPguKHguJfguLXguYjguKPguK3guIfguKPguLHguJo6IHdhbGtpbmcsIHJ1bm5pbmcsIGN5Y2xpbmcsIHN3aW1taW5nLCB5b2dhIikKICAgICAgICAgICAgYWN0aXZpdHkgPSBpbnB1dCgi4LiB4Lij4Li44LiT4Liy4LmA4Lil4Li34Lit4LiB4LiB4Li04LiI4LiB4Lij4Lij4LihOiAiKS5sb3dlcigpCiAgICAgICAgICAgIGR1cmF0aW9uID0gZmxvYXQoaW5wdXQoIuC4geC4o+C4uOC4k+C4suC5g+C4quC5iOC4o+C4sOC4ouC4sOC5gOC4p+C4peC4suC4reC4reC4geC4geC4s+C4peC4seC4h+C4geC4suC4oiAo4LiZ4Liy4LiX4Li1KTogIikpCiAgICAgICAgICAgIAogICAgICAgICAgICBjYWxvcmllc19idXJuZWQgPSBjYWxjdWxhdGVfY2Fsb3JpZXNfYnVybmVkKGFjdGl2aXR5LCB3ZWlnaHQsIGR1cmF0aW9uKQogICAgICAgICAgICBpZiBjYWxvcmllc19idXJuZWQ6CiAgICAgICAgICAgICAgICBwcmludChmIuC4hOC4uOC4k+C5gOC4nOC4suC4nOC4peC4suC4jeC4nuC4peC4seC4h+C4h+C4suC4meC5hOC4myB7Y2Fsb3JpZXNfYnVybmVkOi4yZn0g4LiB4Li04LmC4Lil4LmB4LiE4Lil4Lit4Lij4Li1IikKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIHByaW50KCLguILguYnguK3guJzguLTguJTguJ7guKXguLLguJQ6IOC4geC4tOC4iOC4geC4o+C4o+C4oeC5hOC4oeC5iOC4o+C4reC4h+C4o+C4seC4miIpCi4uLiAoMTEg4Lia4Lij4Lij4LiX4Lix4LiUKQ==
def calculate_bmr(weight, height, age, gender):
"""คำนวณค่า BMR"""
if gender == "male":
bmr = 88.362 + (13.397 * weight) + (4.799 * height * 100) - (5.677 * age)
elif gender == "female":
bmr = 447.593 + (9.247 * weight) + (3.098 * height * 100) - (4.330 * age)
else:
return None
return bmr
def calculate_tdee(bmr, activity_level):
"""คำนวณค่า TDEE"""
activity_multipliers = {
"sedentary": 1.2,
"lightly active": 1.375,
"moderately active": 1.55,
"very active": 1.725,
"extra active": 1.9
}
return bmr * activity_multipliers.get(activity_level, 0) if bmr else None
def calculate_bmi(weight, height):
"""คำนวณค่า BMI"""
bmi = weight / (height ** 2)
if bmi < 18.5:
category = "Underweight"
elif 18.5 <= bmi < 24.9:
category = "Normal weight"
elif 25 <= bmi < 29.9:
category = "Overweight"
else:
category = "Obese"
return bmi, category
def calculate_calories_burned(activity, weight, duration):
"""คำนวณพลังงานที่เผาผลาญจากการออกกำลังกาย"""
met_values = {
"walking": 3.8,
"running": 7.5,
"cycling": 6.8,
"swimming": 8.0,
"yoga": 3.0
}
met = met_values.get(activity, 0)
calories_burned = (met * weight * duration) / 60 if met else None
return calories_burned
def main():
while True:
print("\nโปรแกรมคำนวณสุขภาพ")
print("1. คำนวณ BMI")
print("2. คำนวณ BMR และ TDEE")
print("3. คำนวณพลังงานที่เผาผลาญจากการออกกำลังกาย")
print("4. ออกจากโปรแกรม")
choice = input("กรุณาเลือกเมนู: ")
if choice == '1':
weight = float(input("กรุณาใส่น้ำหนัก (กก.): "))
height = float(input("กรุณาใส่ส่วนสูง (เมตร): "))
bmi, category = calculate_bmi(weight, height)
print(f"ค่า BMI ของคุณคือ: {bmi:.2f}")
print(f"หมวดหมู่: {category}")
elif choice == '2':
weight = float(input("กรุณาใส่น้ำหนัก (กก.): "))
height = float(input("กรุณาใส่ส่วนสูง (เมตร): "))
age = int(input("กรุณาใส่อายุ (ปี): "))
gender = input("กรุณาใส่เพศ (male/female): ").lower()
bmr = calculate_bmr(weight, height, age, gender)
if bmr is None:
print("ข้อผิดพลาด: เพศไม่ถูกต้อง")
continue
print(f"ค่า BMR ของคุณคือ: {bmr:.2f} กิโลแคลอรี")
print("ระดับกิจกรรม: sedentary, lightly active, moderately active, very active, extra active")
activity_level = input("กรุณาใส่ระดับกิจกรรมของคุณ: ").lower()
tdee = calculate_tdee(bmr, activity_level)
if tdee:
print(f"ค่า TDEE ของคุณคือ: {tdee:.2f} กิโลแคลอรีต่อวัน")
else:
print("ข้อผิดพลาด: ระดับกิจกรรมไม่ถูกต้อง")
elif choice == '3':
weight = float(input("กรุณาใส่น้ำหนัก (กก.): "))
print("กิจกรรมที่รองรับ: walking, running, cycling, swimming, yoga")
activity = input("กรุณาเลือกกิจกรรม: ").lower()
duration = float(input("กรุณาใส่ระยะเวลาออกกำลังกาย (นาที): "))
calories_burned = calculate_calories_burned(activity, weight, duration)
if calories_burned:
print(f"คุณเผาผลาญพลังงานไป {calories_burned:.2f} กิโลแคลอรี")
else:
print("ข้อผิดพลาด: กิจกรรมไม่รองรับ")
... (11 บรรทัด)