Exercise 2.3. (The Python if...else Selection Construct)
1. Ensure you have viewed the video (associated with this exercise) at this link >>
2. The flowchart below exhibits the logic for a current account. If the account is overdrawn the customer is fined and charges are applied to the account. However, if the account is not overdrawn then the account is awarded a bonus which is added to the current account balance.
- Sketch the diagram below and highlight the path taken through the chart if the account balance is £200.
- Sketch the diagram again and highlight the path taken through the chart if the account balance is £0.
- Sketch the diagram one more time and highlight the path taken if the account is overdrawn by £150.
3. For the program below which program statement is NOT executed at runtime.
Exercise 2.3. Example 1
4. For the program below which program statement is NOT executed at runtime.
Exercise 2.3. Example 2
5. In your own words describe the difference between the if ... Selection constructure and the if ... else .... Selection construct.
6. Read the following nonsense program and work out what will be displayed i.e. do not just run the program and observe the output. To check your answer, you can then execute the program to see if you were correct. To easily execute the program, you can copy it from this webpage and then paste it into your Python editor and then execute it.
Exercise 2.3. Example 3
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.
END Next Exercise >>