Your school fair card takes top-ups from £5 to £15. Will it accept exactly £15?
At your school fair, you can top up your card with a whole number of pounds. The sign says five to fifteen pounds inclusive. Would exactly fifteen pounds go through? What about sixteen?
Start with a comparison you know. If the amount is five, ask whether it is greater than or equal to five. It is equal, so the comparison gives you true.
Watch both checks for fifteen pounds. It is at least five, and it is at most fifteen. Both checks give true, so the top-up is allowed. The operator that requires both checks to be true is called AND.
The top-up must be at least five pounds and at most fifteen pounds. Check both limits for each amount you see, then pick the one the program should accept.
Another stall accepts eight to twenty pounds inclusive. Python joins the full comparisons with lowercase and. Try twenty-two. Twenty-two is at least eight, so the first comparison is true. It is above twenty, so the second comparison is false. True and false gives false, so the stall rejects the top-up.
This stall accepts top-ups from six to twelve pounds inclusive. You enter thirteen pounds. Check each comparison, then join the results with AND. Pick the option that gives both the correct result and the correct reason.
To detect an amount outside the range, Python checks whether it is less than five or greater than fifteen. Four makes the first comparison true and sixteen makes the second true. Either makes the program print Outside the limits. At exactly five or fifteen, neither comparison is true.
Assume you type a whole number each time. The first line reads your amount. In the while condition, the brackets test whether it is valid. NOT reverses that result, so an invalid amount makes the loop ask again. A valid amount makes the condition false and ends the loop.
Look at the test on the left. Sixteen is at least five, so that test lets it through. On the right, the second comparison checks the upper limit, so sixteen fails. Write out the amount and the comparison on both sides of AND.
Here is an exam-style prompt: explain why the program does not print Accepted when the amount is sixteen. Give both results in order. At least five is true, at most fifteen is false, and AND needs both results to be true.