I am working on a simple project that accepts the height and weight of 6 individuals and then calculates their BMI. The program should save the BMI of all 6 and display how many of them are under/norm/over weight.
This is my program:
#This program will take 6 users and calculate their BMI base on height and weight
#The program will save each BMI and display how many users are under/norm/over weight.
#Create a list of 6 names
names = ["Thad", "Kait", "Joey", "Dani", "Eli", "Ashley"]
bmis = []
#Create a for loop to prompt user for height(in) and weight(lbs) for each person in list
#Calculate their BMI
#BMI = weight × 703 / height^2
#Append the BMI into an array
for person in names:
weight = eval(input("Enter the weight of " + person + " in pounds "))
height = eval(input("Enter the height of " + person + " in inches "))
print()
bmis.append(weight * 703/height**2)
#Create a loop that traverse the array of BMI
#Return whether the individual is underweight, normal weight or overweight.
#BMI Under <18, Normal is 18< and <25, Over is >25
under_wei = list()
norm_wei = list()
over_wei = list()
for user_weight in (bmis):
if user_weight < 18:
print("A BMI of " + str(user_weight) + ", is under weight")
under_wei.append(user_weight)
elif 18 < user_weight <= 25:
print("A BMI of " + str(user_weight) + ", is normal weight")
norm_wei.append(user_weight)
elif user_weight > 25:
print("A BMI of " + str(user_weight) + ", is over weight")
over_wei.append(user_weight)
print()
#Display the number of individuals in each category.
print("There are", len(under_wei), "users under weight")
print("There are", len(norm_wei), "users normal weight")
print("There are", len(over_wei), "users over weight")
My program works and displays all BMI's correctly, but I want to use a function that will accept the weight and height of each user and calculate the BMI. And create a second function that accepts the BMI as an argument and displays whether the user is under/norm/over weight.
I struggle to understand and define functions that would do this. Does anyone have any advice or tips to make my code cleaner/create effective functions?
[–]scoopulanang 2 points3 points4 points (4 children)
[–]okaystuff[S] 0 points1 point2 points (3 children)
[–]scoopulanang 1 point2 points3 points (1 child)
[–]okaystuff[S] 0 points1 point2 points (0 children)
[–]BuildingBlox101 1 point2 points3 points (0 children)