Exercise 2.7 (The Python while loop)
1. Ensure you have viewed the video (associated with this exercise) at this link >>
2. In your own words explain what is meant by the conditional test of a Python while loop.
3. Is the code within a Python while loop (iteration) executed when the test is True or False?
4. Does the conditional test come before or after the program statements within the while loop
5. In your own words describe your understanding of a nondeterministic loop (iteration).
6. Is a Python while loop (iteration) deterministic or nondeterministic
7. For each of the following nonsense programs workout through reading the code the output of each program i.e. do not just execute the program and observe the output.
Exercise 2.7 Example 1
Exercise 2.7 Example 2
Exercise 2.7 Example 3
Exercise 2.7 Example 4
You can check your own answers to the question by copying the code from this webpage, pasting it into your Python editor and executing the program.
Note: To copy the code from webpages on this website place your cursor in the code area, right click the mouse to bring the context menu into view. Select Select all from the context menu this should highlight the code. Ensure the code remains highlighted and click on the right mouse button again and this time select Copy from the context menu that appears. Now paste the copied code into your Python editor and execute the program.
8. Which of the program examples above resulted in the program statement within the loop never executing?
9. Use a while loop to implement the following specification.
Specification
A user is required to enter their name and an integer. The integer specifies how many times their name is to be displayed on the visual display unit (VDU).
Specification
A user is required to enter their name and an integer. The integer specifies how many times their name is to be displayed on the visual display unit (VDU).