Topic 2 - Programming Flashcards
What’s Declaration
Before variables can be used, they must be declared.
Declaring a variable means telling the computer:
What the identifier (name) should be.
What type of data will be stored.
What’s assignment
Changing the value stored inside a variable is called assignment.
The value assigned to a variable must match the data type of the variable.
Why do some languages not need to declare the variable
Some languages don’t need you to declare variables before you use them:
These languages automatically declare the variable before the first assignment.
What’s input
Input is collecting data, usually by the keyboard.
This is written in pseudocode as:
OUTPUT “Please enter [something]…”
variable = USERINPUT
What’s output
Output is putting data to the screen, usually as text.
This is written in pseudocode as:
OUTPUT “Text goes here”
What’s a string
Text data.
Example:
“Hello, world!”.
What’s a character
Character
A single letter of text data.
Example:
‘a’.
What’s a Boolean
A True or False value.
Examples:
True.
False.
What’s a real
Fractional numbers.
Examples:
0.42, 1.00.
What’s an integer
Whole numbers.
Examples:
12, 0, -142.
What are the reasons for casting
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.
What are casting functions
Casting to a string can be done using the str function. E.g:
str(3) gives “3”.
Casting to an integer can be done using the int function. E.g:
int(3.4) gives 3.
Casting to a real can be done using the real function. E.g:
real(“3.4”) gives 3.4.
What are the basic operators
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.
What’s a modulo operators
The modulo operator gives the remainder of the division of two numbers.
For example:
5 MOD 2 would be equal to 1.
What’s integer division
The integer division operator returns the quotient (whole part) of a division.
For example:
5 DIV 2 would give 2.
How do we test for comparisons
We can compare two numbers using the less than and greater than signs. For example:
2 < 3 evaluates to True.
2 > 3 evaluates to False.
We can test for less than or equal, or greater than or equal like this:
2 ≤ 3 evaluates to True.
3 ≥ 3 evaluates to True.
How do you test for equality
We can test if two values are equal using the equality operator. For example:
2 = 2 would evaluate to True.
We can test if two values are not equal using the not-equal-to operator:
2 ≠ 2 would evaluate to False.
What do ORs do
OR evaluates to True if any of the two operands are True: True OR True = True. True OR False = True. False OR True = True. False OR False = False.
What do NOTs do
NOT negates a logical value.
NOT True = False.
NOT False = True
What do ANDs
AND evaluates to True if and only if both operands are True. True AND True = True. True AND False = False. False AND True = False. False AND False = False.
What happens in a sequence algorithm
In a sequence algorithm, the computer follows a series of steps that are executed in the same order every time it runs.
This is often not very useful for longer codes because we cannot use any selection or iteration structures
What happens in a flow chart
The flow chart for a sequence program will have the blocks one by one.
One arrow will connect each block to the next block.
There will be no diamond shapes, so the diagram will be mainly:
Ovals.
Rectangles.
Parallelograms.
What’s selection
Selection allows us to execute a section of code depending on whether a condition is met or not