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.
New to python! Loops
New to python! Loops
|
May-12-2020, 05:00 AM
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:
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
May-13-2020, 04:17 PM
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?
May-15-2020, 02:27 PM
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. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Error in loops, new to Python | jhall710 | 20 | 15,951 |
Apr-25-2017, 05:18 AM Last Post: smbx33 |
Users browsing this thread: 3 Guest(s)