9.3 Programming Flashcards
What is an algorithm?
A set of instructions the computer follows in sequence?
What is a sequence?
The order the program runs in.
What is a variable?
A location in memory that stores one piece of data. It can change as the program runs.
What is iteration?
When a block of code repeats/loops?
What are the two iteration loops used in Python
A for loop is count controlled, whereas a while loop is condition controlled.
Why is iteration used in a program?
To make the program more efficient, e.g. less lines of code so the program runs faster.
What does selection mean?
The user has a choice and the program has different routes to follow based on the choice
What are the key terms you would expect to see when reading a selection statement?
If/elif/else
What is the purpose of indentation
The code belongs to the specific selection statement
Write a print statement
print(‘A print statement’)
Write an input statement for to user entering their name
name = input(‘Enter your name: ‘)
How do the four types of malware get into the computer system:
Virus, worm, trojan and ransomware?
Virus - attaches
Worm - duplicates
Trojan - pretends
Ransomware - locks
What is a list?
A location in memory that stores multiple elements under one name
What is the difference between a variable and a list?
A variable can only store one element whereas a list stores multiple elements.
How is a list defined in Python?
listName = [] (square brackets)
What are the numbers in the binary number line?
128 64 32 16 8 4 2 1
When converted to denary, the binary number 1001 is:
8 + 1 = 9
When converted to binary the denary number 29 is:
29 - 16 = 13
13 - 8 = 5
5 - 4 = 1
11101
Describe how an insertion sort is carried out
An insertion sort is where the numbers are inserted into the correct position. It is the quickest kind of sorting.
Describe how a merge sort is carried out
A merge sort is where we divide and conquer - octo (8) - quads (4) - pairs (2) then sort pairs (2) - quads (4) - octo (8)
Describe how bubble sort is carried out.
In the bubble sort, you sort the pairs:
1st pass - start at 1st item
2nd pass - start at 2nd item
3rd pass - start at 1st item
4th pass - start at 2nd item etc….
Describe how an linear search is carried out
A linear search is where each item in the list is checked until the correct item is found. This can be a slow process if the list is long.
Describe how a binary search is carried out
A binary search is where the list is divided in 2 - is the item you are looking for in the top half or bottom half - get rid of the half of the list it is not in, and repeat the process until you find the item you are looking for.
What is computational thinking?
Computational thinking is about breaking a big problem into smaller manageable problems: Abstraction - selecting the relevant information, Decomposition - breaking it down into steps, Algorithmic thinking - writing short programs for each step.
What is a structure diagram?
A structure diagram is a decomposition tool that shows visually the different steps in solving the problem.
When have I come across computational thinking before?
Maths - BIDMAS: Brackets, Indices , Division, Multiplication, Addition and Subtraction.
What is Python?
Python is a text-based programming language, which is close to the English language and is translated in order for a computer to understand.
What are de Facto standards in programming?
De Facto standards are the expected standard of presentation when writing programs, including title-author-date, this program is designed to… and #comments throughout code.
What is an array?
An array is another word for a list. An array/list store multiple pieces of data in one location.
What is a variable?
A variable stores one piece of data, and can change at the program runs?
How is an array shown in Python?
With a name for the array and square brackets, e.g. studentList = [ ]
What is iteration?
When a block code is repeated either until a condition is met or for a certain number of times.
What key terms would you expect to see when reading iterative statements?
For loop or while loop
What is the purpose of indentation
Repeat the block of code with the iterative statement
What is computational thinking?
Computational thinking is where you take a big problem and break it down into steps and work through logically.
Write a print statement
print(‘A print statement’)
Write an input statement for to user entering their name
name = input(‘Enter your name: ‘)
What does selection mean?
The user has a choice and the program has different routes to follow based on the choice
What are the key terms you would expect to see when reading a selection statement?
If/elif/else
What is the purpose of indentation?
The code belongs to the specific selection statement
What are the numbers in the binary number line?
128 64 32 16 8 4 2 1
When converted to denary, the binary number 1001 is:
8 + 1 = 9
When converted to binary the denary number 29 is:
29 - 16 = 13
13 - 8 = 5
5 - 4 = 1
11101
What are the numbers in the hexadecimal line
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
What is the hexadecimal A4 in binary
8 4 2 1 8 4 2 1
1 0 1 0 0 1 0 0
Describe how an insertion sort is carried out
An insertion sort is where the numbers are inserted into the correct position. It is the quickest kind of sorting.
Describe how a merge sort is carried out
A merge sort is where we divide and conquer - octo (8) - quads (4) - pairs (2) then sort pairs (2) - quads (4) - octo (8)
Describe how bubble sort is carried out.
In the bubble sort, you sort the pairs:
1st pass - start at 1st item
2nd pass - start at 2nd item
3rd pass - start at 1st item
4th pass - start at 2nd item etc….
Describe how an linear search is carried out
A linear search is where each item in the list is checked until the correct item is found. This can be a slow process if the list is long.
Describe how a binary search is carried out
A binary search is where the list is divided in 2 - is the item you are looking for in the top half or bottom half - get rid of the half of the list it is not in, and repeat the process until you find the item you are looking for.
What is a function?
A function changes as the program runs, e.g. calculation (returns a value)
What is a procedure?
A procedure does not change as the program runs, e.g. process (can have a value passed to it)
What is the difference between defining and calling a function
Defining creates the function or procedure which is then called in the main program
How do you read from a file in Python?
“r” - Read - will read a file, e.g.
f = open(“demofile.txt”, “r”)
print(f.readline())
f.close()
How do you write to a file in Python?
“w” - Write - will create a file if the specified file does not exist, e.g.
f = open(“demofile.txt”, “w”)
print(f.readline())
f.close
How do you alter/add to a file in Python?
“a” - Append - will create a file if the specified file does not exist
f = open(“demofile2.txt”, “a”)
f.write(“Now the file has more content!”)
f.close()