pattern_abstraction_flashcards

(20 cards)

1
Q

What is pattern generalisation?

A

Finding common patterns in problems and creating a general solution instead of solving each case individually.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is abstraction?

A

Hiding unnecessary details and focusing on the essential parts of the problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of pattern generalisation in programming.

A

Using a loop to process multiple items instead of writing separate code for each item.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an example of abstraction in programming.

A

Using a function to calculate a bill without worrying about the internal steps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name one part of a programming problem identified by pattern generalisation and abstraction.

A

Variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name three other parts of a programming problem identified by pattern generalisation and abstraction.

A

Input/Output, Calculations/Formulas, Control Structures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are constants?

A

Fixed values that do not change during program execution (e.g., TAX_RATE = 0.2).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why are functions important in abstraction?

A

They allow you to reuse code and hide implementation details. Example: def calculate_bill(units, cost): return units * cost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a data structure?

A

A way to store and organize data (e.g., lists, arrays, dictionaries). Example: usage = [12, 15, 10]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an algorithm?

A

A step-by-step procedure to solve a problem. Example: Sum usage → Multiply by cost → Output bill.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is control flow?

A

The order in which instructions are executed (e.g., loops, conditionals). Example: if bill > 100: print(‘High usage’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why is input validation important?

A

To ensure user input is correct and prevent errors. Example: if not units.isdigit(): print(‘Invalid input’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is output formatting?

A

Presenting results clearly and in a readable format. Example: print(f’Your bill is £{bill:.2f}’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why do we use pattern generalisation?

A

To create reusable solutions and avoid repetitive code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why do we use abstraction?

A

To simplify complex problems by focusing on essential details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Exam-style: Identify 3 parts of a program that can be generalized.

A

Variables, Input/Output, Control Structures.

17
Q

Exam-style: Explain why loops are an example of pattern generalisation.

A

They allow repeated tasks to be handled with one general structure instead of writing separate code for each repetition.

18
Q

Exam-style: Write a Python snippet to calculate weekly electricity bill.

A

units = int(input(‘Enter units: ‘)); cost = 0.15; bill = units * cost; print(f’Bill: £{bill:.2f}’)

19
Q

How does abstraction apply to functions?

A

Functions hide the internal steps and allow you to call them without knowing the details.

20
Q

Give an example of abstraction in real life.

A

Using a car without knowing how the engine works.