What is a variable?
Enjoying Flashcards?
Tell us what you think
What is a variable?
A variable is a named memory location that holds data that during the execution of a program, the data can change.
Define constant.
A constant is fixed data that during the execution of a program cannot change.
What is assignment?
Assignment is the process of storing data in a variable or constant under a descriptive name. E.g. name = "SME"
What is an operator?
An operator is a symbol used to instruct a computer to perform a specific operation on one or more values. E.g. arithmetic, comparison
State four arithmetic operators
Arithmetic operators include:
+, -, *, /
%, //, **
MOD, DIV, ^
State two comparison operators
Comparison operators include:
==
!=
<
>
<=
>=
Define input.
An input is a value that is read from an input device and then processed by a computer program.
True or False?
Without inputs, programs are useful.
False.
Without inputs, programs are not useful as they can't interact with the outside world and always produce the same result.
What is an output?
An output is a value sent to an output device from a computer program.
Typical output devices include?
Typical output devices include:
monitor
speaker
printer.
What is a programming construct?
A programming construct determines the order in which lines of code are executed and controls the logic and behaviour of code.
The three core programming constructs are?
The three core programming constructs are sequence, selection, and iteration.
Define sequence.
Sequence refers to lines of code which are run one line at a time in the order they are written from first to last.
What is selection?
Selection is when the flow of a program is changed depending on a set of conditions, determining which lines or block of code runs next.
Two ways to write selection statements are?
Two ways to write selection statements are: if...then...else statements and case/switch statements.
Define iteration.
Iteration is repeating a line or block of code using a loop.
State two types of Iteration.
Iteration can be count controlled (e.g. for loop) or condition controlled (e.g. while loop).
The keywords indicating selection are?
The keywords indicating selection are if, elseif, else, endif, switch, case.
The keywords indicating iteration are?
The keywords indicating iteration are for, while, do.
If no selection or iteration keywords, the construct is?
If no selection or iteration keywords are present, the construct is sequence.
State the output of 10 MOD 3?
10 MOD 3 = 1
State the output of 10 DIV 3?
10 DIV 3 = 3
State the output of 2 ^ 3?
2 ^ 3 = 8
State the output of 15 % 4?
15 % 4 = 3
State the output of 10 // 2?
10 // 2 = 5
True or False?
A data type classifies data into groups according to the kind of data they represent.
True.
A data type classifies data into groups according to the kind of data they represent.
What is a data type?
A data type is a classification of data into groups according to the kind of data they represent.
Integer
An integer is a data type used for whole numbers like 10, -5, 0.
Real
A real is a data type used for numbers with a fractional part like 3.14, -2.5, 0.0.
Character
A character is a data type used for single characters like 'a', 'B', '6', '£'.
String
A string is a data type used for a sequence of characters like "Hello world", "ABC", "@#!%".
Boolean
A Boolean is a data type used for true or false values like True, False.
What is casting?
Casting is when you convert one data type to another data type.
True or False?
Casting changes the data type within a program.
True.
Casting changes the data type within a program.
State the Python code to cast an integer to a real. The identifier for the variable is X.
real_value = float(X)
State the Python code to cast a real to an integer. The identifier for the variable is X.
int_value = int(X)
State the Python code to cast a Boolean to a string. The identifier for the variable is X.
str_value = str(X)