Question: Execute the code using the following test data then answer the questions: Test data: 10, 101, -1, 5, 0 a) Describe what happened when you
Execute the code using the following test data then answer the questions:
Test data: 10, 101, -1, 5, 0
a) Describe what happened when you entered each value.
b) What does the counter variable do? What does the accumulator variable do?
Why do they have to be initialized to zero before we use them?
c) What type of variable is good data and how is it being used in the program?
Test data: 0
d) Describe what happened when the sentinel value was the first number input.
e) How could we alter the code to prevent this from happening?
b) for loops
Code
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
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
