pythonBMI循环
时间: 2023-10-31 11:54:56 浏览: 82
python实现BMI计算
Sure! Here's an example of a Python program that calculates BMI (Body Mass Index) using a loop:
```python
# BMI Calculation using a loop
# Number of people
num_people = int(input("Enter the number of people: "))
# Loop through each person
for i in range(num_people):
print(f"\nPerson {i+1}")
weight = float(input("Enter weight in kilograms: "))
height = float(input("Enter height in meters: "))
# Calculate BMI
bmi = weight / (height ** 2)
print(f"BMI: {bmi:.2f}")
# Interpret BMI
if bmi < 18.5:
print("Underweight")
elif bmi < 25:
print("Normal weight")
elif bmi < 30:
print("Overweight")
else:
print("Obese")
```
In this program, we first ask the user for the number of people they want to calculate BMI for. Then, using a loop, we prompt for weight and height inputs for each person. The BMI is calculated using the formula weight / (height^2). Finally, we interpret the BMI based on standard ranges and output the result.
Feel free to modify and customize the code according to your specific needs.
阅读全文