I am a bit confused as to why this code only prints “Daniele”, whereas if it’s indented it prints
students_period_A = [“Alex”, “Briana”, “Cheri”, “Daniele”]
students_period_B = [“Dora”, “Minerva”, “Alexa”, “Obie”]
for student in students_period_A:
if you put something in a loop and it gets repeated, that’s not surprising, is it?
I understand why it prints:
but not why Daniele when it’s not indented.
If you print x, then x gets written to screen. You printed a variable, it got written to screen.
Ignore “indentation” and instead ask yourself what and when. Indentation is a small part of how you specify that, so what did you specify?
You used print outside a loop. It printed the thing you told it to print. It happened once because … after executing a statement program control moves on to the next thing, which means that each encountered statement happens once.