Why isn't one of my lists being printed?

I’m a little confused about this exercise. When I put this code in:
for students in students_period_A:
students_period_B.append(students_period_A)
print(students)
I get this output:
Alex
Briana
Cheri
Daniele
My question is why is list B (student_period_B) not also showing if I am adding student_period_A to student_period_B?
My second question is why doesn’t the code work if I have student_period_A.append(student_period_B)?
Thanks in advance

In
for students in students_period_A:
students_period_B.append(students_period_A)
print(students)

The temporary variable students is created and it stores the contents of list A that are selected.
If you print the students variable you will print the contents of list A that are selected.

As for your second question will have to see the code. It should work so it could just be a spelling mistake or a syntax error.

Try to ‘print(students_period_B)’ at the end of the final code, you’ll see List A has been added to List B.

2 Likes

Okay just a heads up, don’t actually do step 3. I ran the infinite loop just to test it like it told me too and this lesson is actually broken for me. I can go back a step, and access other lessons, but I literally can’t continue past this step no matter how many times I sign out and in, refresh, etc. Gonna try clearing cookies now.

4 Likes

for student in students_period_A:
students_period_B.append(student)

for student in students_period_A:
students_period_A.append(student)

Can you please explain to me why the 2nd one creates an infinite loop and the first one no?

In both statements the loop should last for as long as there are a number of students in the students_period_A list, but in the second statement, you’re adding a new student to students_period_A in each iteration.

So, basically the loop is trying to finish, but the the goal keeps getting moved, adding one more student to the list on each iteration. It’ll never complete and becomes infinite.

At least, that’s my understanding. Open to corrections/clarifications.