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

1 Expert Approved Answer
Step: 1 Unlock

A Python for loop iterates over a sequence of elementsIn the first for loop in the example codethe s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!