2 missions. Guess, learn, then check. Your place is saved.
The specification points and sources are listed under the lesson: see Sources.
Make a guess: You typed 41, not 14, for your age. Why did the form accept it?
| Check | What it tests | Example |
|---|---|---|
| Range check | a number is between limits | age 0 to 120 |
| Length check | number of characters | password at least 8 |
| Presence check | something was entered (not empty) | surname not blank |
score = int(input("Score 1 to 10: "))
while score < 1 or score > 10:
score = int(input("Must be 1 to 10: "))name = input("Name: ")
while len(name) < 3:
print("Too short")
name = input("Name: ")
print("Hello " + name)users = [["sam01", "Tr33house"], ["ali22", "Bl0ckH3ad"]]
userID = input("User ID: ")
password = input("Password: ")
found = False
for user in users:
if user[0] == userID and user[1] == password:
found = True
if found:
print("Access granted")
else:
print("Access denied")Validation checks that data is reasonable, such as an age from 0 to 120. 41 follows that rule, so it is accepted even though it is wrong. Only a person who knows the right answer can spot that 41 is the wrong age.
Make a guess: It passed every test. So why did it fail for an 18-year-old?
For a program that accepts whole numbers from 1 to 10:
age = int(input("Age: "))
if age > 18:
print("Adult ticket")
else:
print("Child ticket")The code used > 18 when the rule needed ≥ 18, a mistake that only shows at exactly 18. Testing 10, 30 and 50 only tried normal values; a test at the edge of the range would have caught it.
You've worked through Problem solving with programming for Pearson Edexcel GCSE Computer Science (1CP2). 🎉
Your stars: 0 / 0
Next: test yourself in the Verify stage.
→ Back to GCSE Computer Science · Edexcel
Specification points and sources for this lesson are listed at the bottom of the page.
The specification points and sources behind this lesson.