Why does the code use less than 6 if it needs to stop at 6?

You are adding students to a Poetry class, the size of which is capped at 6.

while len(students_in_poetry) < 6:
student = all_students.pop()


There might be something I’m not seeing here, but if the class is capped at 6, why isn’t len(students_in_poetry)<=6? I tried it this way and it added a 7th student. I thought len(students_in_poetry)<6 would print 5 elements/students.

We go with less than since when there are 5 elements, the code is allowed to run once more. When we allow =6, then the code runs one more time after that, hence it reaches 7.


Understood. Thank you.

1 Like