SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
Programming
Exercise:
Programming Excercises
Question:17 | ISBN:978013274719 | Edition: 6

Question

(Health application: compute BMI) Body mass index (BMI) is a measure of health based on weight. It can be calculated by taking your weight in kilograms and dividing it by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI.Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters.
Here is a sample run:

Enter weight in pounds:95.5
Enter height in inches:50
BMI is 26.8573

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Health application: compute BMI Program code:

# Prompt the user to enter weight in pounds
weightPounds = float(input("Enter weight in pounds: "))

# Prompt the user to enter height in inches
heightInches = float(input("Enter height in inches: "))

# Convert weight from pounds to kilograms
weight_kg = weightPounds * 0.45359237

# Convert height from inches to meters
height_meters = heightInches * 0.0254

# Calculate the BMI by dividing weight in kilograms by the square of height in meters
bmi = weight_kg / (height_meters ** 2)

# Display the calculated BMI
print("BMI is", '{0:.4f}'.format(bmi))

Executed Output:

Enter weight in pounds: 95.5
Enter height in inches: 50
BMI is 26.8573

 

0 0

Discussions

Post the discussion to improve the above solution.