My multiuple choice question is based of the Programming with Python Lesson
What will this loop print to the screen?
index = 1
fruit_name = 'bananas'
for char in fruit_name:
print 'I love ' + char
1. I love bananas
2. b
I love a
I love n
I love a
I love n
I love a
I love s
3. b
a
n
a
n
a
s
4. I love b
I love a
I love n
I love a
I love n
I love a
I love s
What will this loop print to the screen?
fruit_list = ['strawberry','apple','orange','kiwi']
for fruit in fruit_list:
print fruit
1. apple
kiwi
strawberry
orange
2. strawberry
apple
orange
kiwi
3. ['stawberry']
['apple']
['orange']
['kiwi']
4. ['strawberry','apple','orange','kiwi']
['strawberry','apple','orange','kiwi']
['strawberry','apple','orange','kiwi']
['strawberry','apple','orange','kiwi']
Misconceptions
-
Assumption that the list will be sorted while in a loop.
-
Correct Answer.
-
Assumption that the list will be split into smaller lists containing the specified variable.
-
Assumption that the loop will interpret the list as one entity.