How can I advance the exercise after the infinite loop?

This seemed to work for me, I’m really not sure if it’s the direction they wanted us to go through,

for student in students_period_A + students_period_B:

print(student)

1 Like

I didn’t get any output from this. But it helped me to figure it out a way to add the two lists.
I just don’t know if it is the right way, but it worked

Like this:

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

When we add (concatenate) two lists, all the respective values end up in a single list. This is known as extending. Appending means we are inserting an object into an existing list. If that object is a list, then it is a list object that gets appended.

Bottom line,

a = [] print (a + a == []) a.append([]) print (a == [[]])
1 Like

I tried this, its note so fine coding but works

index = 0
leng = len(students_period_A)

while index < leng:
students_period_A.append(students_period_B[index])
print(students_period_A)
index += 1

This is a bit of a trick question with a typo in the code… look closely at what the code does!

index = 0
student = len(students_period_A)

while index < student:
students_period_B.append(students_period_A[index])
print(students_period_B)
index+=1

I thinh that if you remove the indent from the last line {ie. print(students_period_B) }, the concatenated list will only be printed once. Otherwise it will be printed for each student in students_period_A.

for student in students_period_A:
  students_period_B.append(student)
print(students_period_B)
2 Likes

This worked for me

students_period_A = ["Alex", "Briana", "Cheri", "Daniele"] students_period_B = ["Dora", "Minerva", "Alexa", "Obie"] for student in students_period_A: students_period_B.append(student) if len(students_period_B) == 8: for student_total in students_period_B: print(student_total)

There’re a couple different ways to do this exercise. I don’t know how ‘correct’ these two are but they work for me.

Using only for loops

students_period_A = ["Alex", "Briana", "Cheri", "Daniele"] students_period_B = ["Dora", "Minerva", "Alexa", "Obie"] for student in students_period_A: students_period_B.append(student) for student in students_period_B: print(student)

Using no loops at all

students_period_A = ["Alex", "Briana", "Cheri", "Daniele"] students_period_B = ["Dora", "Minerva", "Alexa", "Obie"] students_period_B += students_period_A print(""" """.join(students_period_B))
2 Likes

A little late but thanks for the post. Much like the replies above the simply one loop does not combine both lists into one, which was kind of irritating me as I’m a little anal about wanting to see the final result work like it says. I ran the 2 loops code and it combined everything as it should. Just wanted to say thanks (even a year or so late lol) for posting this.

I think the following code completes the task correctly (i.e. adds the students from one list to the other using a for loop):

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

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

Each time the for loop completes, an element from list A is appended to list B.

After several iterations of the loop, students_period_B contains all the elements from students_period_A

When the loop is complete, the students_period_B list is printed (notice that this instruction is after the indentation but not indented itself and therefore won’t run until the loop is complete).

Hope this helps!