2 Programming Flashcards

1
Q

What is declaration?

A

Declaration is telling the computer what the identifier (name) should be and what type of data should be stored for a variable.

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

What is assignment?

A

The allocation of data values to variables, constants, arrays and
other data structures so that the values can be stored.

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

what is a variable

A

Value that can change during the running of a program. By
convention we use lower case to identify variables (eg a=12)

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

what is a constant?

A

Value that remains unchanged for the duration of the program. By
convention we use upper case letters to identify constants. (e.g. PI=3.141)

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

what are data structures?

A

a data structure refers to a way of organizing and storing data in a computer so that it can be accessed and used efficiently. e.g. arrays, 2-D arrays, data types.

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

what do we use to show indices in python? e.g. if someone wants to find out the answer to 2^3

A

2 ** 3, which equals 8

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

What is input?

A

Input is collecting data, usually through the keyboard
it is data sent to a computer to be processed

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

What is input in pseudocode and in python?

A

psuedocode:
name <— USERINPUT

python:
name = str(input(“Enter your name: “))

psuedocode: variable = USERINPUT

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

What is output?

A

Output is putting data onto the screen, usually as text
it is processed info that is sent out from a computer

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

What is output in pseudocode and in python?

A

psuedocode:
OUTPUT “text”

python:
print(“text”)

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

What are the data types?

A
Character
Real
String
Integer
Boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Character data?

A

Character data is a single letter of text data

Eg. ‘a’

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

What is Real data?

A

Real data is decimal numbers.

Eg. ‘0.55’

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

What is String data?

A

String data is text data (multiple characters).

Eg. “Hello”

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

What is Integer data?

A

Integer data is whole numbers.

Eg. ‘12’

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

What is Boolean data?

A

Boolean data is a true or false value.

Eg. ‘True’ or ‘False’

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

What does the type of data determine?

A

The type of the data determines how it is stored and what you can do with the data.

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

What is casting?

A

Casting is the process of converting data from one type to another.

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

What are the reasons for casting?

A

One of the most common reasons for casting is output.
Output must be formatted as a string, and so we may need to convert a certain piece of data to a string.
All input also comes as a string, and must then be converted to other data types.

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

How do you cast to a string?

A

Casting to a string can be done by using the str function

Eg. str(3) gives “3”

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

How do you cast to an integer?

A

Casting to an integer can be done using the int function. Eg. int(3.4) gives 3

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

How do you cast to a real?

A

Casting to a real can be done using the real function.

Eg. real(“3.4”) gives 3.4

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

What are operators?

A

Operators are symbols that represent a specific function within a program

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

What are the Arithmetic operators?

A

Integer division
Modulus/modulo operator
Basic Operators

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

What is the integer division operator? what do we use to show integer divsion?

A

The integer division operator returns the quotient (whole part) of a division.
Eg. 5 DIV 2 would give 2. the word DIV is used in pseudocode.
the symbol for integer division in python coding is:
5 // 2 = 2

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

What is the Modulus/Modulo operator? what symbol do we use for modulus/modulo in python coding and in psuedocode?

A

The modulus/modulo operator gives the remainder of the division of two numbers.
Eg. 5 MOD 2 would be equal to 1. The word MOD is used in psuedocode.
The symbol in python coding is: 5 % 2 = 1

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

how do we do integer division, including remainders?

A

we would use both DIV and MOD. see pic

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

What are the basic operators?

A
Addition is done using a + sign.
Subtraction is done using a - sign.
Division is done using a / sign.
Multiplication is done using a * sign.
Exponentiation is done using a ** sign.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the relational operator?

A

Relational operators compare two values, and produce a True or False value.

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

What are the Equality operators?

A

We can test if two values are equal using the equality operator.
Eg. 4 == 4 is True
We can also test if two values are not equal using the not-equal-to operator
Eg. 4 ≠ 4 would evaluate to False. that symbol is used in psuedocode to show not equal to. <> is also used in psuedocode to show not equal to.
in python coding, the symbol for not equal to is !=

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

symbol for less than, greater than, less than or equal to and greater than or equal to in pseudocode and in python coding?

A

less than (in python and psuedocode): <
greater than (in python and psuedocode): >
less than or equal to (in python and psuedocode): <=
greater than or equal to (in python and psuedocode): >=

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

What are the Boolean operators?

A

AND
OR
NOT

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

What is the AND Boolean operator?

A
The AND boolean operator evaluates if both operands are True
Eg.
True AND True = True
True AND False = False
False AND True = False
False AND False = False
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is the OR boolean operator?

A
The OR boolean operator evaluates to True if only one of the operands are True.
Eg.
True OR True = True
True OR False = True
False OR False = False
False OR True = True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is the NOT boolean operator?

A

NOT negates a logical value
Eg.
NOT True = False
NOT False = True

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

what do these evaluate to?

7 < 2 and 1 < 2
7 < 2 or 1 < 2
not 7 < 2

A

-> False
-> True
-> True

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

What is Sequence?

A

Sequence is when the computer follows a set of steps in the same order every time it is run.
Each line of code will have some
operation and these operations will be carried out in order line-by-line

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

in python and in psuedocode, how do you generate a random integer?

A

This also includes 1 and 10

python:

import random

#Generate a random integer between 1 and 10

random_integer = random.randint(1, 10)
# 1 and 10 can be generated

print("Random Integer:", random_integer)

psuedocode:

random_integer -> RANDOM_INT(0,9)
OUTPUT random_integer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

in python, how do you generate a random item from a list?

A
import random
#Given a list, pick a random value
my_list = [2, 5, 8, 10]
random_choice = random.choice(my_list)

print("Random Choice:", random_choice)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What is selection?

A

Selection allows us to have decisions made in our program

Selection represents a decision in the code according to some condition. The
condition is met then the block of code is executed otherwise it is not. Often
alternative blocks of code are executed according to some condition

Selection allows us to execute a section of code depending on whether a condition is met or not.

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

What is an If-statement?

A

If-statements is an easy way of checking if a condition is true

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

convert this to psuedocode:
~~~
if i > 2:
j=10
else:
j=3
~~~

A
IF i > 2 THEN
j  <--- 10
ELSE
j <--- 3
ENDIF
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

convert this to python:

IF i ==2 THEN
    j <--10
ELSE IF i==3
    j <-- 3
ELSE
    j <--1
ENDIF
A
if i ==2:
j=10
elif i==3:
j=3
else:
j=1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Which shape is used to show a selection on a flow diagram?

A

Diamond symbol

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

What is Iteration?

A

Iteration allows a group of statements to be repeated multiple times. Iteration statements are often called loops.

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

What is definite iteration? give an example

A

Definite iteration repeats a block of code for a known number of time. For loops are an example. For loops are used when we know before hand the number of iterations we wish
to make.

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

convert to psuedocode:

for a in range(3):
print(a)
A
FOR a ← 0 TO 3 
 OUTPUT a 
ENDFOR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

What is indefinite iteration? give three examples.

A

Indefinite iteration is a block of code that will repeat while a specified condition is true. so we don’t know beforehand the number of iterations that will occur. three examples are: while loop, do…while and repeat…until. these loops are used when we do not know beforehand the number of iterations needed and the block of code will repeat while a specified condition is true.

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

convert to python and what would be the output?

a <-- 0
WHILE a < 4
    OUTPUT a
    a <-- a + 3
ENDWHILE
A
a=0
while a<4:
    print(a)
 a=a+3

output:
0
3

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

use a nested for loop to print out a grid of x’s

A

see pic

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

Use a nested while and if
to print out only even
numbers until and including 50

A

see pic

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

Which shape is used in a flow diagram for iteration?

A

Diamond shape

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

What is a subroutine?

A

A subroutine is a names block of code within your program

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

What are the advantages of a subroutine?

A
  • subroutines can be developed in isolation/independently/separately;
    • easier to discover errors // testing is more effective (than without a
      subroutine);
    • subroutines make program code easier to understand;
    • subroutines make it easier for a team of programmers to work together on
      a large project;
  • subroutines make it easier to reuse code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

How does a subroutine make code easy to read?

A

There are fewer long blocks of code to understand

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

How does a subroutine make the program more efficient?

A

Blocks of code only have to be created once but can be reused multiple times

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

How do subroutines make the program more reliable?

A

If there are bugs in the program, each subroutine can be tested individually to make sure it works

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

What are parameters?

A

Parameters are variables listed inside the parentheses in the function definition (see pic in key points in onenote)
parameters are used to pass data into functions

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

What are arguments?

A

Arguments are the actual values that are sent to the function when it is called (see pic in key points in onenote)

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

What are the two types of subroutine?

A
  • Function
  • procedure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

What is a function?

A

A function is a subroutine which returns a value
A function is a named block of code that takes arguments, manipulates data and returns a value
functions have both input(s) and an output(s)

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

What is a procedure?

A

A procedure is a subroutine which does not return a value
a procedure is a named block of code that performs a set of instructions without returning a value.
a procedure either has an input or an output

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

what is the similarity and difference in the way procedures and functions are set out in Python

A

they are both declared using the def keyword, but a function has a return statement and a procedure does not. Examples:

# A function that returns the square of a number
def square(x):
  return x * x
# A procedure that prints "Hello, world!"
def greet():
  print("Hello, world!")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

What is the scope of a variable?

A

The scope of a variable determines which parts of a program can access and use
that variable

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

What will be the scope of a variable defined within a subroutine?

A

Local scope

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

describe variables with a local scope

A

A variable with a local scope can only be accessed within the subroutine that it is defined in.
Local variables are not recognized outside a subroutine unless they are returned. There is no way of modifying or changing the behavior of a local variable outside its scope.
local variables only exist while the subroutine is executing
Once the execution of the subroutine ends, the local variable is destroyed, and its memory is released

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

What is a global variable?

A

A global variable is a variable that can be accessed by any part of the whole program
A global variable is a variable that can be used anywhere in a program.
they are defined outside of subroutines.

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

How can a variable inside a subroutine be made to have a global scope?

A

A variable can be made global by adding the ‘global’ keyword in front of it the first time it is used

see pic

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

compare global variables with local variables

A

The issue with global variables is that one part of the code may inadvertently modify the value because global variables are hard to track. also, global variables need to defined throughout the running of the whole program.
This is an inefficient use of memory resources.

Local variables are defined only when they are needed and so have less demand on memory. also, the localised scope of local variables makes it easier to debug programs because any issues related to a local variable are confined to a specific part of the code. in addition, local variables are held in RAM only during the execution of the corresponding subroutine. Once the subroutine completes, the local variable is no longer retained in memory. This efficient use of system resources contrasts with global variables, which remain in memory throughout the entire program execution. also, When using local variables, programmers can reuse the same variable names for different purposes within different subroutines. This flexibility helps prevent accidental conflicts between variables with the same name.

but, local variables only exist within a subroutine, so cannot be accessed by other parts of the programme, and sometimes, programmes need variables that can be accessed throughout the whole programme.

70
Q

what is structured programming?

A

Structured programming is the process of breaking down a large problem into a set of smaller problems
The smaller sub-problems are then used to:-
Working out the parameters needed
Decide which data type would be the most appropriate
Work if out if a value is needed to be returned
these sub-problems allow the larger programme to be programmed in a modular manner, so that each section of the programme can be coded one by one.

71
Q

use the structured programming technique to decompose the task of making a computer game

A

Modern computer games are decomposed to break down the complexity of the problem into more manageable ‘chunks’
Creating an entire game at once would be challenging and inefficient, so it could be decomposed into:
Levels - Levels can be designed/created/tested/ independently of other levels
Characters - The mechanics of characters in the game can be designed and created by a separate team
Landscape - The art team can work on the visual aspects of the game without needing to understand how the game is programmed
Once all of the smaller problems are completed, joined together a complex game has been created

72
Q

what is a hierarchy chart?

A

A hierarchy chart is an example of a diagram used to show problem decomposition in structured programming
Each problem is divided into multiple subproblems, which is turn are divided into further subproblems until they cannot be divided any further
Hierarchy charts show how module and subroutines relate to each other and is depicted as a tree structure
Hierarchy charts can be created on paper or digitally and can also be created programmatically by software
An example of a hierarchy chart is shown below for a sending messages and calls on a mobile phone. Each sub-problem is broken down into smaller sub-problems:

73
Q

Mabel is a software engineer. She is writing a computer game for a client. In the game the main character has to avoid their enemies. This becomes more difficult as the levels of the game increase.

The computer game allows a user to select a character (e.g. name, gender). They can then choose a level for the game (easy, normal, challenging). The user controls their character by moving it left or right. The character can jump using space bar as an input. If the character touches one of the enemies then it loses a life. The character has to make it to the end of the level without losing all their lives.

The game is designed in a modular way.
One sub-procedure will handle the user input.
Describe three other sub-procedures Mabel could create for the given game description. [6]

A

Mabel could create a sub-procedure to select a character, including name and gender, etc [1], which gives the user options when choosing a character [1]

Mabel could create a sub-procedure to choose a level [1] which gives the user a choice of difficulty (easy, medium, challenging) by taking the user input [1]

Mabel could create a sub-procedure to allow the character to lose lives [1]. If the character has less than 0 lives left then the game ends [1]

74
Q

benefits of decomposition/structured programming

A

When developing code for a large problem or project, decomposition/structured programming can be used to divide the code into manageable sections, so that the coder can code different parts of the programme in an organised manner without being overwhelmed by the whole project at once. Another benefit is that error detection and debugging is made easier when you focus on smaller sections of code. Also, decomposition can be used when working in a group, so you can distribute different sub-problems to different people to solve, according to their strengths.

75
Q

What is an array?

A

An array is a data structure that stores a fixed number of values under a single identifier.

76
Q

if we want to access a file in our code, what do we need to do?

A

Whatever we are doing to a file whether we are reading, writing or adding to or modifying a file we first need to open it using:
open(filename,access_mode)

There are a range of access mode depending on what we want to do to the file, the principal ones are given in the pic:

77
Q

When storing values in an array what must the values all be?

A

The values must be of the same type.

78
Q

When are Arrays useful?

A

Arrays are useful when you have lots of related data that you don’t want to store in multiple variables

79
Q

What is an element?

A

An element is each piece of data inside an array

80
Q

What is an element’s index?

A

An element’s index is it’s position within the array. The counting of the elements starts at zero

81
Q

format of an array

A

primes = [2, 3, 5, 7, 11, 13]

82
Q

How would you assign values in an array?

A

name_of_array[x] = “Hello”

x is the element number you wish to put the value number into

83
Q

How can you access values within an array?
how to get 5 from this array?
primes = [2, 3, 5, 7, 11, 13]

A

OUTPUT name_of_array[x]
x is the element number you wish to access
The first element is at index 0, so primes[2] gives us the value 5.

84
Q

What do lists store?

A

Lists store multiple elements under the same identifier.

85
Q

What is the maximum number of elements a list can have?

A

There can be a variable number of elements - they never get full.

86
Q

how to find the length of an array?
what is the length of this array?
list = [“banana”, “apples”, “blueberries”]

A

using len(name_of_array)
the length of that array is 3.

87
Q

How can lists be declared?

A

A list can be declared as follows:

list = []

88
Q

How can values be added to the end of the list?

A

Values can be added to the end of the list as follows:

list.append[“value”]

89
Q

What is a 2D (2-Dimensional) array?

A

A 2D array is the data structure which consists of a list of lists.
Example: multiples = [[2, 4, 6, 8, 10], [3, 6, 9, 12, 15]]

90
Q

how to access an individual list in a 2D list?
multiples = [[2, 4, 6, 8, 10], [3, 6, 9, 12, 15]]
how to access the first list of this 2D array?

A

we use name of list followed by index position of list.

multiples = [[2, 4, 6, 8, 10], [3, 6, 9, 12, 15]]

multiples[0] gives us the first list.

91
Q

How would you access an individual element in a 2D array?
How to get 8 and 15 from this 2D list?
multiples = [[2, 4, 6, 8, 10], [3, 6, 9, 12, 15]]

A

To access a specific value, we use row and column indices, e.g., multiples[0][3] gives us 8, and multiples[1][4] gives us 15.

92
Q

What are the uses of a 2D list?

A

A 2D list could be used for a 2D surface or a database

93
Q

How can a 2D list be used for a database?

A

Each inner list can store a record of the database

The outer list can store each record

94
Q

What is a string?

A

Strings are special cases of arrays or lists, where each element is a character

95
Q

What is concatenation?

A

Concatenation is joining two strings together. This can be done with the + sign.
Eg. “Hello” + “World” = “Hello World”

96
Q

How would we access a character in a string?

A

str[3]

This accesses the 4th character in the string

97
Q

How would we see the length of a string?

A

Use the len function

Eg. len(“Hello”) would give 5

98
Q

What are the string operations?

A
  • Length
  • Substring
  • Concatenation
99
Q

what is a substring?
how to extract a substring?
extract the first three characters of the word “Computer”

A

Definition: A substring is a sequence of characters that exists inside a string. For example, you might want to extract the first three characters of a password or a specific section of a longer text.
Syntax:
To extract a substring, you use a process called slicing. You specify the start and end positions within the original string.
The syntax looks like this: string[start:end]

100
Q

defintion of concatenation

A

concatenation refers to the process of joining two or more strings together to create a new string.

101
Q

What is the purpose of files??

A

Files allow us to store data so it continues even when the program is not running
Files allows programs to carry on where they left off when they are executed

102
Q

What are text file made up of?

A

String data

103
Q

What is binary files mad up of?

A

Binary data

104
Q

Why should we be careful with the way we handle data?

A

We should be careful with the way we handle data so we do not accidentally corrupt them

105
Q

How do we open a file so the operating system knows we are using it?

A

We can use these commands:
openRead(“filename.txt”)
openWrite(“filename.txt”)

106
Q

How do we assign a variable to a file?

A
MyVariable = openRead("filename.txt")
MyVariable = openWrite("filename.txt")
107
Q

How do we read/write in a file?

A

We use the following commands:
myFile.readLine() will return the next line of a file as a string.
myFile.writeLine() will write a line to the file.
myFile.endOfFile() will return True if we reach the end of the file.

108
Q

How do we close a file?

A

We can close a file using the following command:

myFile.close()

109
Q

What is structured data?

A

Structured data refers to any data that resides in a fixed field within a record or file so that it can be easily entered, stored, queried, and analysedof records

110
Q

What are the pros and cons of records?

A

Pros:
Very simple, text-based format.
Can be read by many applications.
Easy to use in programs.

Cons:
Inefficient for large datasets.
Can only store text data.
No built-in means of sorting or searching.

111
Q

What are comma separated values (CSV)?

A

CSV is one method of storing a record
Each record is stored on its own line
Each field is separated by a special character such as a comma

112
Q

What are records made up of?

A

Fields

113
Q

in python, create a record of students using this information, then output this information in this exact format.

A

see pic

114
Q

What are identifiers?

A

Identifiers are the names given to variables, constants, and subroutines

115
Q

How should variables be named?

A

Variables should be be lowercase and an underscore should separate each word. They should also have descriptive names
Eg. this_is_my_variable

116
Q

How should constants be named?

A

Constants should be named the same as variables (an underscore separates each letter and they should have descriptive names) but unlike variables the letters are uppercase

117
Q

How should subroutines be named?

A

Subroutines should have lowercase names, with each word separated by an underscore
Eg. calculate_sum()
Subroutines should have descriptive names where possible

118
Q

What is Whitespace?

A

Whitespace is key to good code, since it is used to separate blocks of code and make code easier to read.

119
Q

When should blank lines generally be used?

A

Subroutines should be separated by a blank line.
Blank lines can be used sparingly in subroutines to show sections of the subroutine.
Other lines of code should not have blank space around them.

120
Q

What are comments?

A

Comments are lines of code that are ignored completely by the computer
They are used to add description to your code to make it easy to understand
A Python comment is preceeded by a #

121
Q

Why is indentation necessary in some coding languages?

A

Indentation is necessary in some languages to control program flow

122
Q

What is an interface?

A

An interface is a collection of comments which describe a subroutine.

An interface includes:
List of parameters and their types.
Return value and its type.
What the subroutine does.

123
Q

What do validation and sanitation protect against?

A

Validation and sanitation can help to protect against malicious inputs such as SQL injection attacks

124
Q

What is input sanitation?

A

Input sanitation involves the removal of unwanted characters from input data
Any data entered by users which might be executed or become part of a query should first be sanitised.

125
Q

What is input validation?

A

Input validation is the process of making sure that input data meets certain criteria.
If a user’s data is rejected, they should be informed and asked to enter it again

126
Q

What are the input validation rules?

A
Input validation rules include:
Type checks
Range checks
Presence checks
Format checks
Length checks
127
Q

What are type checks?

A

Type checks check the type (e.g. Integer) of the input

128
Q

What are range checks?

A

Range checks check that the data is inside an allowed range, e.g. less than 100

129
Q

What are presence checks?

A

Presence checks check that the required data has been input

130
Q

What are format checks?

A

Format checks check that the data fits a set format, e.g. an email address has an @ symbol

131
Q

What are length checks?

A

Length checks check that the number of characters entered is inside a permitted range.

132
Q

What is Contingency planning?

A

Contingency planning is a course of action designed to help someone respond to a future event or situation that may happen
This includes:
Providing helpful prompt messages
Providing error-recovery routes (e.g. an undo feature)
Preventing access from certain parts of the system
Using exception handling

133
Q

What is authentication?

A

Authentication is the process of checking that a person or system is authorised to use a system.

134
Q

What is the most common form of authentication?

A

The most common form of authentication is to require users to enter a username and password.

135
Q

What happens when a user is authenticated?

A

Once a user has authenticated themselves, they should be able to see data relevant to themselves and no one else.

136
Q

What are errors in software often called?

A

Bugs

137
Q

what are syntax errors? examples of syntax errors

A

Errors in the code that mean the program will not even run at all.
Normally this is things like missing brackets, spelling mistakes and other typos.
Examples of syntax errors are:
Typos and spelling errors
Missing or extra brackets or quotes
Misplaced or missing semicolons
Invalid variable or function names
Incorrect use of operators
Incorrectly nested loops & blocks of code

138
Q

what are runtime errors?

A

Errors during the running of the program. This might be because
the program is writing to a memory location that does not exist for instance. eg.
An array index value that does not exist.

139
Q

what are logic errors? examples of logic errors?

A

The program runs to termination, but the output is not what is expected. Often these are arithmetic errors.
examples:
Division by 0
Incorrect use of operators (< and >)
Logical operator confusion (AND for OR)
Looping one extra time
Indexing arrays incorrectly (arrays indexing starts from 0)
Using variables before they are assigned
Infinite loops

140
Q

see pic

A

see pic

141
Q

What gets rid of bugs?

A

Debugging

142
Q

What are the purposes of testing?

A

The purposes of testing are to check that a program:
Works as intended under good conditions
Copes with errors when given bad data

Testing involves inputting test data into the programme to check if the output given is what the expected output is. Code needs to be tested with a range of different input data to ensure that it works as expected under all situations.

we need to ensure that data entered into the programme is checked by the programme to make sure that the input values are:

  • within a certain range
  • in correct format
  • the correct length
  • The correct data type (eg float, integer, string)
143
Q

What does debugging means?

A

Debugging is to find the cause of the bug and fix it

144
Q

Are bugs deliberate attempts to bring down systems?

A

No

145
Q

What are some different types of testing in the development stages?

A

Performance and load testing
Usability testing
Functionality testing
Security testing

146
Q

When does terminal testing occur?

A

Terminal testing occurs at the end of development

147
Q

What are the results of terminal testing used for?

A

The results of terminal testing are used to check how the software performs when given a certain set of test data.

148
Q

When does Iterative testing occur?

A

Iterative testing involves testing code as it is written

149
Q

What are the results of iterative testing used for?

A

The results of iterative testing are fed back into the development process

150
Q

What is test data?

A

Test data involves using a range of data, both valid and invalid, to see how the program responds
Code needs to be tested with a range of different input data to ensure that it works as expected under all situations.

151
Q

What are the different types of data used in testing?

A

The program is tested using normal (typical), erroneous or boundary (extreme) data.
Normal data - Data that we would normally expect to be entered. For example for
the age of secondary school pupils we would expect integer values ranging from 11
to 19.
Erroneous data - Data that are input that are clearly wrong. For instance, if some
entered 40 for the age of a school pupil. The program should identify this as
invalid data but at the same time should be able to handle this sensibly which
returns a sensible message and the program does not crash.
Boundary data - Data that are on the edge of what we might expect. For instance
if someone entered their age as 10, 11, 19 or 20.

152
Q

What are test plans?

A

Test plans are created to make sure that testing is effective by detailing which test will be performed, which test data will be used, and what the intended outcome will be

153
Q

When should a test plan be created?

A

A test plan should be made before development and is part of the design stage

154
Q

SME Electronics is an online shop which sells electronic items.
The following flowchart shows an algorithm used to calculate the price of an item when they have a sale.

A

see pic

155
Q

What are High-level languages?

A

High-level languages include most programming languages such as Python, C++ and Java

156
Q

What are High-level languages (HLLs) made up of?

A

High-level languages are made up of human-readable statements which makes it easy to understand

157
Q

What does it mean when High-level languages (HLLs) are portable?

A

High level languages are portable, which means that they can be run on many different types of hardware

158
Q

Why don’t we always use High-level languages (HLLs)?

A

Computers can only process instructions in the form of binary numbers. We have to use special HLL software which translates our HLL source code into executable binary

159
Q

What are Low-level languages (LLLs)?

A

Low-level programming languages are languages which are much closer to computer-understandable binary.

160
Q

Why do we use Low-level languages (LLLs)?

A

LLLs provide exact control over the central processing unit
LLLs need less translation, and often lead to faster code which is useful for computers with low specifications such as embedded systems

161
Q

What are translators?

A

Translators are special software that convert source code into executable binary

162
Q

What are compilers?

A

Compilers are software that translates the whole of a program in one go
Eg. C, C++, Visual Basic and Swift

163
Q

What are the pros of compilers?

A

Compilers produce an executable program:
There is no need to repeat this process more than once per version of the software.
Compilers hide the source code from the end user. This helps to protect developers’ intellectual property.
Compilers will provide a list of errors once it has attempted the compilation process. This can make debugging easier.

164
Q

What are the cons of compilation?

A

The compilation process can be very slow, this slows development if small changes need to be made

165
Q

What are Interpreters?

A

Interpreters are are a type of translator which convert high level languages to executable machine code
Eg. Python and JavaScript

166
Q

What are the cons of Interpreters?

A

Running an interpreted program is slower than a compiled program because we have to translate each line every time we run the software
But it is quicker to get started which can be good for small changes
Interpreters do not produce a compiled program file:
The process must be repeated each time the program is run

167
Q

What are the pros of interpreters?

A

Interpreters stop as soon as they encounter an error. This is useful for debugging
Interpreted languages are portable. This means they can be run on many different types of CPU’s as long as there is an interpreter available for the platform

168
Q

What do assemblers do?

A

Assemblers translate assembly code into executable binary

169
Q

What is Assembly?

A

Assembly is a low-level language where each instruction directly responds to a binary sequence and the assembler replaces the commands with the relevant binary

170
Q

What are the pros of assemblers?

A

Assembly provides exact control over the hardware:
This can lead to very efficient code that takes up little space in memory and is quick to execute.
Assembly can be used on low specification machines.

171
Q

What are the cons of assemblers?

A

Assembly is very difficult to use, and needs deep technical knowledge of the central processing unit and the memory.