calculate BMI (Body Mass Index):
def calculate_bmi(weight, height): return weight / (height**2) weight = float(input("Enter your weight in kilograms: ")) height = float(input("Enter your height in meters: ")) bmi = calculate_bmi(weight, height) print("Your BMI is:", round(bmi, 2)) In this program, `calculate_bmi` is a function which takes weight and height as parameters and returns the BMI. The weight and height are taken as user input using the `input` function, and then the BMI is calculated and stored in the `bmi` variable. Finally, the BMI is printed using the `print` function. The `round` function is used to round the BMI to two decimal places for better readability.
Comments
Post a Comment