Help with Lists/Loops in Python3


#1

So for my programming class, the assignment is to “create an array of the days of the week, then create a loop to print the content”. I am not sure if I am understanding the question correctly. So, the following is what I came up with but I know there has to be an easier way to get the desired effect. Any advice is welcome. (Also for some reason I cant figure out how to get my indents to display so imagine an indent prior to each print statement)

Days = [[“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”]]
print (Days)
for Monday in (Days):
print (“Monday”)
for Tuesday in (Days):
print (“Tuesday”)
for Wednesday in (Days):
print (“Wednesday”)
for Thursday in (Days):
print (“Thursday”)
for Friday in (Days):
print (“Friday”)
for Saturday in (Days):
print (“Saturday”)
for Sunday in (Days):
print (“Sunday”)


#2
Days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

for day in Days:
    print(day)

#3

Can you explain that a little? I don’t really understand the concept of the “for day in Days” part, where does day come from? It isnt defined prior, so is the for statement itself defining each item within Days as day and then just running through each element?


#4

you nailed it
The name day is local to the loop. Each element inside Days has its turn being the day…every day gets printed
You could have said for puppies in Days and gotten the same result