What is pattern generalisation?
Finding common patterns in problems and creating a general solution instead of solving each case individually.
What is abstraction?
Hiding unnecessary details and focusing on the essential parts of the problem.
Give an example of pattern generalisation in programming.
Using a loop to process multiple items instead of writing separate code for each item.
Give an example of abstraction in programming.
Using a function to calculate a bill without worrying about the internal steps.
Name one part of a programming problem identified by pattern generalisation and abstraction.
Variables.
Name three other parts of a programming problem identified by pattern generalisation and abstraction.
Input/Output, Calculations/Formulas, Control Structures.
What are constants?
Fixed values that do not change during program execution (e.g., TAX_RATE = 0.2).
Why are functions important in abstraction?
They allow you to reuse code and hide implementation details. Example: def calculate_bill(units, cost): return units * cost
What is a data structure?
A way to store and organize data (e.g., lists, arrays, dictionaries). Example: usage = [12, 15, 10]
What is an algorithm?
A step-by-step procedure to solve a problem. Example: Sum usage → Multiply by cost → Output bill.
What is control flow?
The order in which instructions are executed (e.g., loops, conditionals). Example: if bill > 100: print(‘High usage’)
Why is input validation important?
To ensure user input is correct and prevent errors. Example: if not units.isdigit(): print(‘Invalid input’)
What is output formatting?
Presenting results clearly and in a readable format. Example: print(f’Your bill is £{bill:.2f}’)
Why do we use pattern generalisation?
To create reusable solutions and avoid repetitive code.
Why do we use abstraction?
To simplify complex problems by focusing on essential details.
Exam-style: Identify 3 parts of a program that can be generalized.
Variables, Input/Output, Control Structures.
Exam-style: Explain why loops are an example of pattern generalisation.
They allow repeated tasks to be handled with one general structure instead of writing separate code for each repetition.
Exam-style: Write a Python snippet to calculate weekly electricity bill.
units = int(input(‘Enter units: ‘)); cost = 0.15; bill = units * cost; print(f’Bill: £{bill:.2f}’)
How does abstraction apply to functions?
Functions hide the internal steps and allow you to call them without knowing the details.
Give an example of abstraction in real life.
Using a car without knowing how the engine works.