← QCE Digital Solutions Unit 1

Dependability of a program

A dependable program works correctly and reliably every time, even when users enter unexpected or invalid input, because it handles errors instead of crashing.

Understanding Dependability of a program in QCE Digital Solutions Unit 1

What it does: A reliable function always returns the correct result for the same valid input. Checking the input before using it lets the program respond to invalid data instead of failing. Dependability also means coping with unexpected or invalid input, not just the ideal case. try/except catches the ValueError when the user types something that is not a whole number, so the program does not crash. You can't stop users making mistakes, but you can make the program respond safely to them. Reliable programs behave consistently and correctly each time they are used. A validation loop rejects invalid values and repeats the request, which makes the program more reliable.

Common mistakes: Python does not use catch. The error handler must be written as 'except ValueError:' so invalid input is handled instead of crashing. Converting with int() before checking crashes the program if the user types letters. Keep the input as text, check it with isdigit(), and convert afterwards.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 158–380) and word search (Modules 82–380).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which program is more dependable?
One that gives a clear message when a user types letters instead of a numberOne that crashes when a user types letters instead of a number
Matches
age = int(input('Age: ')) print(age + 1)
↓
Typing letters such as 'abc' causes a ValueError and crashes the program, because there is no error handling.
Applying
Meanings
Term
dependability
Meaning
A dependable program works correctly and reliably every time, even when users enter unexpected or invalid input, because it handles errors instead of crashing.
Practice
age_text = "abc"
Testing
Gaps
:
Check Answer
Spots
2 age = int(input('Age: '))
3catch ValueError:

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Desert Tortoise' badge — Desert Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which program is more dependable?
A. One that crashes when a user types letters instead of a number
B. One that gives a clear message when a user types letters instead of a number ✓
A dependable program handles unexpected input and keeps working instead of crashing.
2. True or false: A program that works with perfect input every time is automatically dependable.
A. False ✓
B. True
Dependability also means coping with unexpected or invalid input, not just the ideal case.
3. A user enters -5 for their age. Which response shows a dependable program?
A. Show an error message and ask for the age again ✓
B. Accept -5 and carry on using it
Checking for invalid input and asking again stops bad data spreading through the program.
4. Which code is better for dependability?
A. try: n = int(input()) except ValueError: print('Numbers only') ✓
B. n = int(input())
try/except catches the ValueError when the user types something that is not a whole number, so the program does not crash.
5. What does error handling help a program do?
A. Make sure no user ever makes a mistake
B. Keep running or fail safely when something goes wrong ✓
You can't stop users making mistakes, but you can make the program respond safely to them.

Match the Pairs

try: age = int(input()) except ValueError: print('Enter a number') → Catches bad input so the program shows a message instead of crashing
while age < 0 or age > 120: age = int(input('Age: ')) → Keeps asking until the input is valid, so bad data never gets used
Reliability: the program gives the right result every time it is run with valid input → def add(a, b): return a + b
Handling invalid input: check the input before using it → if not name.isdigit(): print('Numbers only')
age = int(input('Age: ')) print(age + 1) → Typing letters such as 'abc' causes a ValueError and crashes the program, because there is no error handling.
try: n = int(input()) except: pass → The error is silently ignored, so n is never set and the program fails later without telling the user what went wrong.

Key Term

dependability
A dependable program works correctly and reliably every time, even when users enter unexpected or invalid input, because it handles errors instead of crashing.

Fill in the Blanks

1. try: n = int(input("Number: ")) except ValueError:
Hint: Type the keyword that starts a block of code which might cause an error.
2. try: n = int(input("Number: ")) except ValueError:
Hint: Type the error type raised when text cannot be converted to a number.
3. age = int(input("Age: ")) while age < 0: age = int(input("Age: "))
Hint: Type the comparison operator that detects an invalid negative age so the program asks again.
4. if count != 0: print(total / count)
Hint: Type the operator that checks the count is not zero, so the program avoids a crash from dividing by zero.
5. except ValueError: print("Please enter a number")
Hint: Type the function that shows a friendly message to the user instead of letting the program crash.

Spot the Error

Question 1
A try:
B age = int(input('Age: '))
C catch ValueError:
D print('Enter a number')
Line C — Python does not use catch. The error handler must be written as 'except ValueError:' so invalid input is handled instead of crashing.
Question 2
A while True:
B n = int(input('Number: '))
C if n.isdigit():
D break
E print(int(n))
Line B — Converting with int() before checking crashes the program if the user types letters. Keep the input as text, check it with isdigit(), and convert afterwards.
Question 3
A def safe_div(a, b):
B if b == 0:
C return a / b
D return a / b
Line C — Inside the zero check the function still divides by b, so it crashes with ZeroDivisionError. It should return a safe value such as None.
Question 4
A try
B f = open('data.txt')
C except FileNotFoundError:
D print('File missing')
Line A — A try block must end with a colon. It should be 'try:' so the error handling code is valid.
Question 5
A score = input('Score: ')
B if score.isdigit():
C print('Invalid score')
D else:
E print('Saved')
Line B — The condition is inverted. Valid digits would be reported as invalid. It should be 'if not score.isdigit():' so only bad input is rejected.

Student with a class code? Join your class →