dcf.cymru stimulus sheet · Computer Science · Year 11
The pool, the client and the program are invented for practice. This is not your class’s Unit 2 pre-release brief. The Python is real and runs exactly as described.
Pwll Glan-y-Dŵr is a small leisure centre pool. Its manager, Siw Morgan, asked a developer for a program that books children onto blocks of swimming lessons at the reception desk. These are her requirements.
| Ref | Requirement |
|---|---|
| R1 | The receptionist types the child’s surname, age and the number of lessons in the block. |
| R2 | The age must be a whole number from 4 to 16, including 4 and 16. Anything else is rejected with the message Age must be 4 to 16. |
| R3 | The number of lessons must be a whole number from 1 to 10, including 1 and 10. Anything else is rejected with the message Lessons must be 1 to 10. |
| R4 | Each lesson costs £6.50. A block of 6 or more lessons gets 10% off the total. |
| R5 | The booking reference is the first 3 letters of the surname in capitals, followed by the age. Jones, aged 9, is JON9. |
| R6 | The program must never crash, whatever the receptionist types. |
In the finished system these functions are called when the receptionist clicks a Tkinter Book button. Here input() and print() stand in for the entry boxes and the message label, so you can trace it on paper. The developer says it “works fine”. Siw is not so sure.
| Code | What happens |
|---|---|
| int("12") | Gives the whole number 12. |
| int("ten"), int(""), int("9.5") | The program crashes with ValueError: invalid literal for int() with base 10. Nothing after that line runs. |
| "12".isdigit() | True: every character is a digit. |
| "ten".isdigit(), "".isdigit(), "-3".isdigit(), "9.5".isdigit() | False every time. |
| A and B | True only when both A and B are true. |
| A or B | True when at least one of A and B is true. |
| "Jones"[0:3] | "Jon": characters 0, 1 and 2. .upper() then makes it "JON". |
| f"£{3.9:.2f}" | £3.90: always 2 decimal places. |