a) A Python for loop iterates? Describe what that means using the first two for loops in
Fantastic news! We've Found the answer you've been seeking!
Question:
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()
Related Book For
Financial Accounting and Reporting a Global Perspective
ISBN: 978-1408076866
4th edition
Authors: Michel Lebas, Herve Stolowy, Yuan Ding
Posted Date: