Py4e: Chapter 5- Questions and Answers|
Latest Update
What is the iteration variable in the following Python code:
friends = ['Joseph', 'Glenn', 'Sally']
for friend in friends :
print('Happy New Year:', friend)
print('Done!') Correct Ans-friend
What is a good description of the following bit of Python code?
zork = 0
for thing in [9, 41, 12, 3, 74, 15] :
zork = zork + thing
print('After', zork) Correct Ans-Sum all the elements of a list
What will the following code print out?
smallest_so_far = -1
for the_num in [9, 41, 12, 3, 74, 15] :
if the_num < smallest_so_far :
smallest_so_far = the_num
print(smallest_so_far) Correct Ans--1
Latest Update
What is the iteration variable in the following Python code:
friends = ['Joseph', 'Glenn', 'Sally']
for friend in friends :
print('Happy New Year:', friend)
print('Done!') Correct Ans-friend
What is a good description of the following bit of Python code?
zork = 0
for thing in [9, 41, 12, 3, 74, 15] :
zork = zork + thing
print('After', zork) Correct Ans-Sum all the elements of a list
What will the following code print out?
smallest_so_far = -1
for the_num in [9, 41, 12, 3, 74, 15] :
if the_num < smallest_so_far :
smallest_so_far = the_num
print(smallest_so_far) Correct Ans--1