Question: a) A Python for loop iterates? Describe what that means using the first two for loops in the example code. b) What does the range()
a) A Python for loop iterates? Describe what that means using the first two for loops in the example code.
b) What does the range() function do? What happens when one, two, and three arguments are used with the range function?
c) In most languages, altering the counting variable that is being used to control a for loop in the body of the loop can cause problems and lead to the loop not executing the desired number of times. In the last for loop in the example, the count variable is being altered. Is this causing problems with the number of loop repeats? Why or why not?
def main():
for day in ('Sunday', 'Monday', 'Tuesday'):
print(day)
print()
for count in [0,1, 2, 3, 4, 5, 6, 7, 8, 9]:
print(count)
print()
for count in range(10):
print(count)
print()
for count in range(1, 10):
print(count)
print()
for count in range(1, 10, 3):
print(count)
print()
for count in range(10):
count += 1
print(count)
print()
main()
Step by Step Solution
3.48 Rating (155 Votes )
There are 3 Steps involved in it
A Python for loop iterates over a sequence of elementsIn the first for loop in the example codethe s... View full answer
Get step-by-step solutions from verified subject matter experts
