Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to python! Loops
#1
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.
Reply
#2
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
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.
Reply
#3
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?
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in loops, new to Python jhall710 20 12,193 Apr-25-2017, 05:18 AM
Last Post: smbx33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020