Question

In: Computer Science

Write a Python program to determine the body-mass index of a collection of six individuals. Your...

Write a Python program to determine the body-mass index of a collection of six individuals. Your program should include a list of six names. Using a for loop, it should successfully prompt the user for the height in inches and weight in pounds of each individual. Each prompt should include the name of the individual whose height and weight are to be input. It should call a function that accepts the height and weight as parameters and returns the body mass index for that individual using the formula weight × 703 / height2. That body mass index should then be appended to an array. Using a second loop it should traverse the array of body mass indices and call another function that accepts the body mass index as a parameter and returns whether the individual is underweight, normal weight, or overweight. The number of individuals in each category should be counted and the number in each of those categories should be displayed. You should decide on the names of the six individuals and the thresholds used for categorization.

Solutions

Expert Solution

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote

CODE:

# function that accepts the height and weight as parameters and

# returns the body mass index

def calculate_bmi(height, weight):

    bmi = weight * (703/(height ** 2))

    return bmi

# function that accepts the body mass index as a parameter and

# returns whether the individual is underweight, normal weight, or overweight

def bmi_category(bmi):

    #conditions

    if ( bmi < 16):

        return "underweight"

    elif ( bmi >= 16 and bmi <= 25):

        return "normalweight"

    elif (bmi > 25):

       return "overweight"

   

#program starts here

#creating list of six names

name_list = ["Adam", "Eden", "Tom", "George", "Nina", "Cody"]

bmi_list = [] #declare an empty list for bmi

for name in name_list: #loop through each name in name_list

    # getting height and weight for each person

    height = float(input(name + ", Enter your height in inches: "))

    weight = float(input(name + ", Enter your weight in pounds: "))

    bmi = calculate_bmi(height, weight) #calculating the bmi for particular person

    bmi_list.append(bmi) #appending the bmi to bmi_list

#initialize number of underweight, normalweight and overweight persons as 0

num_under = 0

num_normal = 0

num_over = 0

for bmi in bmi_list: #loop through each bmi in bmi_list

    category = bmi_category(bmi) #finding the category

    if category == "underweight": #increment num_under by 1 if category is underweight

        num_under = num_under + 1

    elif category == "normalweight": #increment num_normal by 1 if category is normalweight

        num_normal = num_normal + 1

    elif category == "overweight": #increment num_over by 1 if category is overweight

        num_over = num_over + 1

#displaying the number of individuals in each category

print("\nNumber of underweight persons: ", num_under)

print("Number of normalweight persons: ", num_normal)

print("Number of overweight persons: ", num_over)

OUTPUT:


Related Solutions

This involves writing a Python program to determine the body-mass index of a collection of six...
This involves writing a Python program to determine the body-mass index of a collection of six individuals. Your program should include a list of six names. Using a for loop, it should successively prompt the user for the height in inches and weight in pounds of each individual. Each prompt should include the name of the individual whose height and weight is to be input. It should call a function that accepts the height and weight as parameters and returns...
Using class, write a program that: Body Mass Index (BMI) calculation - write a program that...
Using class, write a program that: Body Mass Index (BMI) calculation - write a program that takes users' input (weight and Height) and calculates the BMI. If the result is less than 18.5 display "you are underweight", if the result is greater than 18.5 display "you have a normal weight", if the result is greater than 24.9 display "your weight is considered overweight", and the result is greater than 30 display "your weight is considered as obese" (BMI = 703...
A common characterization of obese individuals is that their body mass index is at least 30...
A common characterization of obese individuals is that their body mass index is at least 30 [BMI = weight/(height)2, where height is in meters and weight is in kilograms]. An article reported that in a sample of female workers, 266 had BMIs of less than 25, 158 had BMIs that were at least 25 but less than 30, and 123 had BMIs exceeding 30. Is there compelling evidence for concluding that more than 20% of the individuals in the sampled...
A common characterization of obese individuals is that their body mass index is at least 30...
A common characterization of obese individuals is that their body mass index is at least 30 [BMI = weight/(height)2, where height is in meters and weight is in kilograms]. An article reported that in a sample of female workers, 262 had BMIs of less than 25, 156 had BMIs that were at least 25 but less than 30, and 123 had BMIs exceeding 30. Is there compelling evidence for concluding that more than 20% of the individuals in the sampled...
A common characterization of obese individuals is that their body mass index is at least 30...
A common characterization of obese individuals is that their body mass index is at least 30 [BMI = weight/(height)2, where height is in meters and weight is in kilograms]. An article reported that in a sample of female workers, 266 had BMIs of less than 25, 159 had BMIs that were at least 25 but less than 30, and 120 had BMIs exceeding 30. Is there compelling evidence for concluding that more than 20% of the individuals in the sampled...
A common characterization of obese individuals is that their body mass index is at least 30...
A common characterization of obese individuals is that their body mass index is at least 30 [BMI = weight/(height)2, where height is in meters and weight is in kilograms]. An article reported that in a sample of female workers, 264 had BMIs of less than 25, 157 had BMIs that were at least 25 but less than 30, and 121 had BMIs exceeding 30. Is there compelling evidence for concluding that more than 20% of the individuals in the sampled...
programming in Python The body mass index (BMI) is calculated as a person’s weight (in lb)...
programming in Python The body mass index (BMI) is calculated as a person’s weight (in lb) times 720, divided by the square of the person’s height (in inches). A BMI in the range 19-25, inclusive, is considered healthy. Write a program that inputs people’s weight and height, then calculates a person’s BMI and print a message telling whether they are above, within, or below the healthy range. A formula for computing Easter in the years 1982-2048, inclusive, is as follows:...
In Java, need to create a program with Body Mass Index (BMI) is a measure of...
In Java, need to create a program with Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing, 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 one pound is 0.45359237 kilograms and one inch is 0.0254 meters. Here is a sample run: Enter weight in...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Design a modular program that calculates and displays a person's body mass index (BMI). The BMI...
Design a modular program that calculates and displays a person's body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. A person's BMI is calculated with the following formula: BMI=Weight*703/Height^2. I need help making this to Java to just calculate BMI.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT