Definite Iteration

Computer Science Master

Question 1. What is definite iteration?

□ A. Iterating until a condition becomes false with an unknown number of loops

□ B. Repeating a fixed number of times, such as looping through a list

□ C. Repetitive execution with no condition to stop

□ D. Running loops based on user input

Question 2. Which part of a for loop checks if the loop should continue or stop?

□ A. Initialization □ B. Update □ C. Condition □ D. Execution block

Question 3. In the Python range() function, what does the 'stop' parameter represent?

□ A. The number included in the sequence

□ B. The first number generated by range()

□ C. The number at which the sequence stops, but is not included

□ D. The step size between numbers

Question 4. What is the default step value in the range() function if not specified?

□ A. 0 □ B. 1 □ C. 2 □ D. Undefined

Question 5. Consider the loop: for i in range(3): print(i). How many times will the print statement execute?

□ A. 2 □ B. 3 □ C. 4 □ D. 5

Question 6. Fill in the blank(s)

The three parts of a for loop include _____________________, _____________, and _________.

Question 7. Fill in the blank(s)

In Python's range() function, if you omit the start value, it defaults to _.

Question 8. Fill in the blank(s)

The stop value in range(start, stop, step) is _____________, meaning it is not included in the generated sequence.

Question 9. Fill in the blank(s)

In definite iteration, the loop runs a __________________ of times.

Question 10. Fill in the blank(s)

The default step size in the range() function is _ if not otherwise specified.

Question 11. Explain what happens during the 'update' phase of a for loop.

Question 12. Describe what the range(0, 10, 2) function call does.

Question 13. What does the for loop 'for i in range(5): print(i)' output?

Question 14. In the context of Python for loops, what type of object does the range() function return?

Question 15. Why does the loop terminate when using a range() function?

Question 16. Describe the process of definite iteration using a for loop in Python, including the role of initialization, condition, and update.

Question 17. Explain how the range() function works in Python and how it facilitates definite iteration within for loops.

Question 18. Discuss why understanding the exclusive nature of the 'stop' parameter in range() is important when writing for loops.

Definite Iteration

Answer Sheet

Question 1. What is definite iteration?

A. Iterating until a condition becomes false with an unknown number of loops

□ B. Repeating a fixed number of times, such as looping through a list

C. Repetitive execution with no condition to stop

D. Running loops based on user input

Question 2. Which part of a for loop checks if the loop should continue or stop?

A. Initialization B. Update □ C. Condition D. Execution block

Question 3. In the Python range() function, what does the 'stop' parameter represent?

A. The number included in the sequence

B. The first number generated by range()

□ C. The number at which the sequence stops, but is not included

D. The step size between numbers

Question 4. What is the default step value in the range() function if not specified?

A. 0 □ B. 1 C. 2 D. Undefined

Question 5. Consider the loop: for i in range(3): print(i). How many times will the print statement execute?

A. 2 □ B. 3 C. 4 D. 5

Question 6. Fill in the blank(s)

The three parts of a for loop include [[Initialization]], [[Condition]], and [[Update]].

Question 7. Fill in the blank(s)

In Python's range() function, if you omit the start value, it defaults to [[0]].

Question 8. Fill in the blank(s)

The stop value in range(start, stop, step) is [[exclusive]], meaning it is not included in the generated sequence.

Question 9. Fill in the blank(s)

In definite iteration, the loop runs a [[fixed number]] of times.

Question 10. Fill in the blank(s)

The default step size in the range() function is [[1]] if not otherwise specified.

Question 11. Explain what happens during the 'update' phase of a for loop.

The loop variable is modified, usually incremented, after each iteration to move towards the termination condition.

Question 12. Describe what the range(0, 10, 2) function call does.

It generates a sequence of numbers from 0 up to but not including 10, increasing by 2 each time; so the numbers 0, 2, 4, 6, 8.

Question 13. What does the for loop 'for i in range(5): print(i)' output?

It outputs the numbers 0, 1, 2, 3, and 4 each on a new line.

Question 14. In the context of Python for loops, what type of object does the range() function return?

It returns a range object, which is an iterable representing a sequence of numbers.

Question 15. Why does the loop terminate when using a range() function?

Because once the loop variable reaches the stop value (exclusive), there are no more numbers left to iterate, so the condition becomes false.

Question 16. Describe the process of definite iteration using a for loop in Python, including the role of initialization, condition, and update.

Question 17. Explain how the range() function works in Python and how it facilitates definite iteration within for loops.

Question 18. Discuss why understanding the exclusive nature of the 'stop' parameter in range() is important when writing for loops.