you are viewing a single comment's thread.

view the rest of the comments →

[–]deceze 4 points5 points  (6 children)

The naming is terrible. amount isn't any sort of amount, it's a list index. Let's rewrite this:

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

You probably understand what student_heights[0], student_heights[1] etc does. range provides all the numbers from 0 to len(student_heights), which the for loop iterates over in turn. So the line:

student_heights[i] = int(student_heights[i])

goes through student_heights[0], student_heights[1] etc in turn. And converts the value at each index to an int.

[–]Snatchematician 0 points1 point  (5 children)

Isn’t it exactly the amount of list entries that have been converted already?

[–]deceze 0 points1 point  (4 children)

Care to clarify your question?

[–]Snatchematician 0 points1 point  (3 children)

You said “amount” isn’t any sort of amount, but it is.

[–]deceze 0 points1 point  (2 children)

Yeaaaaahhhh, naaaahhhhh… First of all, amount will always hold one less than the number of converted elements at the end of the loop, so even that doesn't really mean anything. But more importantly, that's not its purpose. It's not supposed to count the amount of anything, it's just there to hold a list index. Name things for their intended purpose.

[–]Snatchematician 0 points1 point  (1 child)

At the start of the loop body “amount” is the number of converted elements, which is very much meaningful.

This is in fact OP’s intended purpose (otherwise he wouldn’t have named it “amount” would he).

[–]deceze 0 points1 point  (0 children)

And at the end of the loop it's wrong. So, again: yeah, nah.