Python Forum

Full Version: New to python! Loops
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have been given a problem asking for the BMI of each person in the list using a loop. There are 6 sublists within the list we will call person_data. In the sublist contain [name,weight,hight]. I know that BMI=weight/height**2. I'm just having a problem running the loop to calculate each BMI for each person. I know I'm missing something simple. Am I supposed to index the BMI equation? I'm trying to use a for loop. I created a he blank BMI list.Any help is greatly appreciated.
There are several options, one of them presented below (unpack, calculate, output):

spam = [[5, 6, 7], [50, 60, 70]]
for item in spam:
    first, second, third = item
    print(f'{first}: {second * third}')
Output of this code will be:

Output:
5: 42 50: 4200
If you are in the US you also need to convert the height to meters and the weight to kilograms.

What format are you looking for with your output?
This is homework, we will help you but first you have to show what you have. First make the list.
person_data = []
person_data.append(['Seeley', 82, 1.92])
person_data.append(['Jeff', 95, 1.86])
# ...
print(person_data)
Now continue. Chop chop.