I have a question about a particular line of code

for n in range(0, len(student_heights)):
  student_heights[n] = int(student_heights[n])

From the above code,

student_heights[n] = int(student_heights[n])

can someone please explain this line to me, i get the rest of the code

Hello, @Supratit , welcome to the world of Python!

A line like

student_heights[n] = int(student_heights[n])

is very normal in software in general, including in Python. How about you explain what you have figured out about that line, and what still confuses you? Then we can help you with the parts you don’t get yet.

i got the part about n being a number between 0 and length of the list student_heights, my question is do they take a number, for example 0, pick out the element which is at the 0 position in the list, turn it into an integer and then put it back in the same position?

Yes, that is exactly what that line does. You understand the Python syntax well.

The code you showed does not explain what values are in the list, nor what meaning those values have for the outside world.

Yes sorry about that part, I didn’t share the full code, thank you for helping me though :slight_smile:

1 Like

When you are not sure what the code is doing, try inspecting the variables with print() to see what they are.

input() returns a string, and the string split() method breaks it up into a list of words.

So if you enter “123 456 789”, student_heights will be a list of three words:

['123', '456', '789']

The line student_heights[n] = int(student_heights[n]) then grabs the n-th word, converts it to an int, and puts it back in the list. So you will end up with:

[123, 456, 789]

Thank you for your help :slight_smile: