New to python! Loops - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: New to python! Loops (/thread-26739.html) |
New to python! Loops - Seeley307 - May-12-2020 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. RE: New to python! Loops - perfringo - May-12-2020 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:
RE: New to python! Loops - jefsummers - May-13-2020 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? RE: New to python! Loops - ibreeden - May-15-2020 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. |