Kalkulator BMI:
BMI ialah cara cepat dan murah untuk mengkategorikan berat badan seseorang sebagai kurang berat badan, normal, berat badan berlebihan atau obes.
Formula BMI:
BMI dikira dengan membahagikan berat dengan ketinggian kuasa dua:
Unit metrik:
BMI = berat (kg) / [tinggi (m)]2
Unit biasa AS:
BMI = berat (paun) / [tinggi (dalam)]2 x 703
Contoh:
# Input the weight in kilograms weight = float(input("Enter your weight (in kg): ")) # Input the height in meters height = float(input("Enter your height (in meters): ")) # Calculate BMI using the formula: bmi = weight / (height ** 2) # Output the calculated BMI value print("BMI:", round(bmi, 2)) # Rounds BMI to 2 decimal places # Function to provide feedback based on BMI def bmi_feedback(bmi): if bmi < 18.5: return "You are underweight" elif 18.5 <= bmi <= 24.9: return "You have a healthy weight" elif 25 <= bmi <= 29.9: return "You are overweight" else: return "You are obese" # Call the feedback function and store the result bmi_result = bmi_feedback(bmi) # Output the BMI category feedback print("BMI Result:", bmi_result)
Output:
Enter your weight:58 Enter your height:1.67 BMI: 20.796729893506402 BMI Result: You have a healthy weight
Atas ialah kandungan terperinci Tulis program Python ke kalkulator BMI. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!