FAQ: Learn Python: Loops - Infinite Loops


#1

This community-built FAQ covers the “Infinite Loops” exercise from the lesson “Learn Python: Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Infinite Loops

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

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


#3

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.


#4
# I want to make it clear I will be using very little python verbage to explain this in plain english.

students_period_A = ["Alex", "Briana", "Cheri", "Daniele"]
students_period_B = ["Dora", "Minerva", "Alexa", "Obie"]

for student in students_period_A:
  # student is the temporary variable.  This is what we are going to call in each list.
  # You want to put A into B.  So "A" is going to be the focus for the statement.
  -----------.append()
  # So now, each students_period_A is now counted as "students".  So you want to........ 
  # If you print it you should see only four people, as it is only wanting to print the students, not the variable
  print(student)

#6
for student in students_period_A:
  students_period_B.append(student)
  print(student)