Paper 2 Programming Techniques Flashcards
What is a variable?
Variables are data values that can change when the user is asked a question, for example, their age. Variables may change during program execution.
What is a constant?
Data values that stay the same every time a program is executed are known as constants
State the ‘data types’ required for the following variables: student_name
Text / String
State the ‘data types’ required for the following variables: student_age
Float i.e. 16.5 years
Integer i.e. 16 years
Date - Date of Birth (can work out a persons age by calculation)
State the ‘data types’ required for the following variables: student_sex
Boolean (m/f)
State the ‘data types’ required for the following variables: student_height
Float i.e. - 5ft 10 inches
Integer i.e. - 178 cms
State the ‘data types’ required for the following variables: student_first_initial
Char (only one letter)
Name the 3 constructs of a programming language
- sequence is the order in which instructions occur and are processed.
- selection determines which path a program takes when it is running.
- iteration is the repeated execution of a section of code when a program is running.
Explain the difference between how FOR loops and WHILE loops control the flow of instructions during the running of a program.
For loop contains only a single condition whereas while loop may contain a set of commands to be executed together.
In for loop, initialization of command is done only once but in while loop initialization of command is needed each time the iteration of command is done
An operator is something which will perform an action on some data. What does an arithmetic operator do?
Arithmetic operators allow arithmetic to be performed on values such as + - / *
An operator is something which will perform an action on some data. What does a relational operator do?
Relational operators allow for assignment and enable comparisons to be made. They are used in condition testing such as ==, >, < , <=, >=
An operator is something which will perform an action on some data. What does a Boolean operator do?
Logical operators are used to combine relational operators to give more complex decisions such as AND, OR, NOT
What is an array (or list in Python)?
An array is a data structure that holds similar, related data. An array is like a collection of boxes, each of which is called an element . Each element has a position in the array, and can hold a value. The data in an array must all be of the same data type .
For the given array:
my_array = [“train”, “walk”, “car”, “bus”, “cycle”]
…how would you access the 3rd item?
my_array[2]
Arrays (or lists in Python) always has the first element as 0
What is the difference between a 1-dimensional array and a 2-dimensional array?
The main difference between 1D and 2D array is that the 1D array represents multiple data items as a list while 2D array represents multiple data items as a table consisting of rows and columns. … The elements in the array are in subsequent memory locations.