Python Strings Medical Insurance Project help

Welcome to the Get Help category!
[https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-strings/projects/ds-python-strings-project]

I am attempting the extra work (task #22) in the Python Strings Medical Insurance Project. The task is this:

  • 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......

We already have separated out all of the relevant information into separate lists of: names, ages, bmis, insurance_costs.

My attempted code looks like this:

for i in names:
i = 0
print(names[i] + ’ is ’ + ages[i] + ’ years old with a BMI of ’ + bmis[i] + ’ and an insurance cost of ’ + insurance_costs[i] + β€˜.’)
i += 1

The output prints the same information ten times, all of it the information for indices[0]. Why is it not moving to the next indices when it prints? Any help would be great!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!
  • Remember to include a link to the exercise you need help with!
  • If someone answers your question, please mark their response as a solution :white_check_mark:
  • Once you understand a new concept, come back and try to help someone else!

@txg8r,

Take a look at your for loop. What is the first thing that happens on each iteration of the loop?

I was having nightmare with this as well but I got it to work this way.

for i in range(len(names)):
name = names[i]
age = ages[i]
bmi = bmis[i]
insurance_cost = insurance_costs[i]
print(str(name)+ ’ is ’ +str(age)+ ’ year olds with a BMI of ’ + str(bmi)+ ’ and an insurance cost of '+ str(insurance_cost))

I am sure there is another way to use medical_record_clean list rather than separate lists on which we ended up on at the end of the project as well but I couldn’t get that to work.

1 Like

Not really sure what you’re trying to get me to see/understand with my first line el_cocodrilo, but apparently adding the range(len(names)) while deleting the counter did the trick and got each line to print correctly.

for i in range(len(names)):

  print(names[i] + ' is ' + ages[i] + ' years old with a BMI of ' + bmis[i] + ' and an insurance cost of ' + insurance_costs[i] + '.')

f
This code does the same job without having to do the name = names[i] part