Help on Loops!

Believe me when I say I can’t for the life of me figure this one out.

all_students = ["Alex", "Briana", "Cheri", "Daniele", "Dora", "Minerva", "Alexa", "Obie", "Arius", "Loki"]
students_in_poetry = []

while (students_in_poetry < 6):


Why is this wrong?

what are you comparing here:

while (students_in_poetry < 6):

looks your checking if a list is less then 6. Doesn’t this result in a TypError? Comparing two types (list and integer) which can’t be compared

what should you compare here?


I should be checking if the students_in_poetry is less than 6, should I use range()? Or maybe something else?

Also, a few things to consider:

  • When you do all_students.pop(), where does the popped element go? It doesn’t look like you are storing it anywhere
  • When you do students_in_poetry.append(student) have you defined student before trying to append it here to a list? This might be related to the point above :wink:
  • Like @stetim94 said, what are you trying to do with the comparison? You are checking if the total number of students in students_in_poetry is less than 6 right? Can you think of a way to check the length of that list so that you can do your < 6 comparison?
1 Like

Ohhhhh, I need to use len(students_in_poetry) and then check if it’s less than six, so the code line should be while (len(students_in_poetry) < 6): instead of while (students_in_poetry < 6): right?

That makes sense to me! Just run it and see, that’s the awesome part of coding: you get to break it again and again haha