Python Strings: Medical Insurance Project Extra Task

Hello guys, here I have a question about the extra task in the string medical insurance project:
Here I have 4 lists:

Names: [‘MARINA ALLISON’, ‘MARKUS VALDEZ’, ‘CONNIE BALLARD’, ‘DARNELL WEBER’, ‘SYLVIE CHARLES’, ‘VINAY PADILLA’, ‘MEREDITH SANTIAGO’, ‘ANDRE MCCARTY’, ‘LORENA HODSON’, ‘ISAAC VU’]
Ages: [‘27’, ‘30’, ‘43’, ‘35’, ‘22’, ‘24’, ‘51’, ‘19’, ‘65’, ‘34’]
BMI: [‘31.1’, ‘22.4’, ‘25.3’, ‘20.6’, ‘22.1’, ‘26.9’, ‘29.3’, ‘22.7’, ‘33.1’, ‘24.8’]
Insurance Costs: [’$7010.0’, ‘$4050.0’, ‘$12060.0’, ‘$7500.0’, ‘$3022.0’, ‘$4620.0’, ‘$16330.0’, ‘$2900.0’, ‘$19370.0’, ‘$7045.0’]

And the task is to write a for loop that outputs a string for each individual in the following format:

Marina is 27 year olds with a BMI of 31.1 and an insurance cost of $7010.0.
Markus is 30 years old with a BMI of 22.4 and an insurance cost of $4050.0

I have tried different ways such as:
for name in names:
for age in ages:
for bmi in bmis:
for insurance_cost in insurance_costs:
print(name + " is " + str(age) + " year olds with a BMI of " + str(bmi) + " and an insurance cost of " + insurance_cost + “.”)

and
for name, age, bmi, insurance_cost in names, ages, bmis, insurance_costs:
return "{} is {} year olds with a BMI of {} and an insurance cost of {}. ".format(name, age, bmi, insurance_cost)

Both of my ways are wrong. So I wonder what code I should put for this for loop.

Thanks a lot and happy coding! :slight_smile:

https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-strings/projects/ds-python-strings-project

Here is the link

Hello! Since each element in the lists corresponds to the other lists; the first element of the names list is to do with Marina Allison, the first element of the ages list is to do with Marina Allison, etc, you could consider using range(). I will give this as a first hint; if you need more, just ask!

Thank you so much for your hint. But I’m just wondering how can I connect all these lists into a for loop? Could you please give me another hint? Thanks a lot! :slight_smile:

You can either use range() and list indexing, or you can use this approach (which still requires list indexing):

x = [9,8]
y = [8,9]
for i in x,y:#this is similar to using zip. The variable i holds a list
#which contains the first values of x&y on, the first iteration,
#the second values of x&y on the second iteration, and so forth
  print(i)
#prints:
#[9,8]-the value of i on the first iteration
#[8,9]-the value of i on the second iteration
1 Like

Thank you for your reply, and I’ve been trying the way you’re telling. But seem I’m stuck…
And I came up the following code, but unfortunately, I’m still bit confused.

for i in range(len(names)), range(len(ages)), range(len(bmis)), range(len(insurance_costs)):
  print(names[i] + " is " + str(ages[i]) + " year olds with a BMI of " + str(bmis[i]) + " and an insurance cost of " + insurance_costs[i] + ".")

I do apologize if I sound stupid for you but would be nice if you could give more hints…
Thank you so much and happy new year.

With the last code snippet, you are pretty close. See my last post about what happens when you do for i in x,y. What is i? What data type is i? You have used multiple range(len(x)), but why? What does range(len(x)) return? If each list is the same length, does that hint towards anything? Same, uni, one?
I’ll leave it at that, but if you need more, I’m more than happy to help! And happy New Year to you as well!

Please help with other hints

Please don’t cross-post to multiple topics as mentioned in the community guidelines-Guidelines - Codecademy Forums