Exercise 2.6 (Python elif ... Selection Clause)
1. Ensure you have viewed the video (associated with this exercise) at this link >>
2. The following specification is followed by the Python code that implements the specification. Read the code (but do not execute it) and answer the following questions:
a). How many different routes (paths) are there through the code?
b). Which print statement is executed when the user enters 16 for their age?
c). What would be printed on the Visual Display Unit (VDU) if the user entered 17 for their age?
d). Which print statement is executed when the user enters 18 for their age?
e). What would be printed on the VDU if the user entered 19 for their age?
Specification
Write a program that asks the user to enter their age. If they are 18 or older the program reports back their age and asks them to collect their polling card. If the user enters 17 the program reports back their age and informs them that they can vote next year. However, if they are not old enough to vote and are not 17 the program again reports back their age, but this time tells them that they are too young to vote
a). How many different routes (paths) are there through the code?
b). Which print statement is executed when the user enters 16 for their age?
c). What would be printed on the Visual Display Unit (VDU) if the user entered 17 for their age?
d). Which print statement is executed when the user enters 18 for their age?
e). What would be printed on the VDU if the user entered 19 for their age?
Specification
Write a program that asks the user to enter their age. If they are 18 or older the program reports back their age and asks them to collect their polling card. If the user enters 17 the program reports back their age and informs them that they can vote next year. However, if they are not old enough to vote and are not 17 the program again reports back their age, but this time tells them that they are too young to vote
Exercise 2.5 This implements the above specification (Example 1)
3. Amend the above program so that the print statements contain the new Python f string. Search the web for Python f string to help you with this task. Please note that I have covered the use of the f string in the tkinter section of this website. However, I have used the f string in this video in a different context.
4. Implement the following specification using Python with the if … elif … else .. Selection construct.
Specification
Individuals who are 65 or over can apply for a concessionary travel card. If they are at least 65 years of age the following is displayed on the VDU:
You may apply for the concessionary travel card.
If they are 64 the following string is displayed:
You can apply on or after your next birthday.
For all other ages less than the qualifying age the following is displayed:
Sorry you are not old enough to apply for a concessionary travel card.
Test the runtime of your program with a suitable test plan that ensures full boundary testing.
Specification
Individuals who are 65 or over can apply for a concessionary travel card. If they are at least 65 years of age the following is displayed on the VDU:
You may apply for the concessionary travel card.
If they are 64 the following string is displayed:
You can apply on or after your next birthday.
For all other ages less than the qualifying age the following is displayed:
Sorry you are not old enough to apply for a concessionary travel card.
Test the runtime of your program with a suitable test plan that ensures full boundary testing.
END Next Exercise >>