Question

In: Computer Science

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 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.

Your program should include the pseudocode used for your design in the comments. Document the thresholds you chose for under weight and over weight in your comments as well.

Solutions

Expert Solution

Code + Pseudocode + threshold used:


#function to calculate bmi
def bmi(h,w):
    bmi=(w*703)/(h**2)   #bmi formula
    
    return bmi

#fumction to find category according to bmi
def bmi_category(bmi):
    if bmi<18.5:
        return 1
    elif bmi>=18.5 and bmi<=24.9:
        return 2
    elif bmi>=25:
        return 3
    
    
#main program

#list of names
li_name=["a","b","c","d","e","f"]

#list of bmi initialized
li_bmi=[0,0,0,0,0,0]


#calculating bmi from input of height and weight of each name
for i in range(6):
    print("\nEnter height in inches of",li_name[i],": ",end="")
    h=float(input())
    print("\nEnter weight in pounds of",li_name[i],": ",end="")
    w=float(input())
    li_bmi[i]=bmi(h,w)

#initialize count for each category
count_underweight=0
count_normalweight=0
count_overweight=0

#initialize list of names under each category
li_under=[]
li_normal=[]
li_over=[]

#finding category of each bmi
for i in range(6):
    x=bmi_category(li_bmi[i])
    if x==1:
        count_underweight = count_underweight + 1
        li_under.append(li_name[i])
    elif x==2:
        count_normalweight = count_normalweight + 1
        li_normal.append(li_name[i])
    elif x==3:
        count_overweight = count_overweight + 1
        li_over.append(li_name[i])
        

#printing output

print("\n\nNumber of under weight persons =",count_underweight,"\n",li_under)
print("\n\nNumber of normal weight persons =",count_normalweight,"\n",li_normal)
print("\n\nNumber of over weight persons =",count_overweight,"\n",li_over)
        


#####################################################
    
#pseudocode
# 1. initialize name_list of 6.
# 2. initialize bmi_list of 6.
# 3.for each name in name_list, update corresponding bmi in bmi_list by taking its height and weight as input.
# 4.for each bmi in bmi_list find category of bmi according to threshold.
# 5.update count of bmi category and list of category with corresponding name.
# 6.print output as count and list of names for each category.


#threshold
# bmi categories:
# Under weight = <18.5
# Normal weight = 18.5–24.9
# Over weight = 25–29.9

OUTPUT:


Related Solutions

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...
The sixth assignment involves writing a Python program to read in the temperatures for ten consecutive...
The sixth assignment involves writing a Python program to read in the temperatures for ten consecutive days in Celsius and store them into an array. The entire array should then be displayed. Next each temperature in the array should be converted to Fahrenheit and the entire array should be again be displayed. The formula for converting Celsius to Fahrenheit is °F = (°C × 1.8) + 32. Finally, the number of cool, warm and hot days should be counted and...
The second assignment involves writing a Python program to compute the price of a theater ticket....
The second assignment involves writing a Python program to compute the price of a theater ticket. Your program should prompt the user for the patron's age and whether the movie is 3D. Children and seniors should receive a discounted price. There should be a surcharge for movies that are 3D. You should decide on the age cutoffs for children and seniors and the prices for the three different age groups. You should also decide on the amount of the surcharge...
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...
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...
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.
Discuss the process of calculating Body Mass Index (BMI).
Discuss the process of calculating Body Mass Index (BMI).
This project involves writing a program to calculate the terms of the following sequence of numbers:...
This project involves writing a program to calculate the terms of the following sequence of numbers: 0 1 1 3 5 11 21 43 … where each term is twice the second previous term plus the previous term. The 0th term of the sequence is 0 and the 1st term of the sequence is 1. The example below shows how to calculate the next sequence term: Current sequence: 0 1 Calculate next term: 2 * 0 + 1 = 1...
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT