Topics 1-3 Flashcards
What’s a high-level language?
Designed for humans, easier to learn/use.Incl. libraries of pre-built automations (‘functions’). E.g. Python, Java, C++.
Must be translated into machine language for CPU to understand.
What’s a low level language?
Close to what computer speaks, difficult for humans to read. Include assembly languages & machine code.
What is an Interpreter?
Translates high-level language into machine code one instruction at a time, immediately executes that instruction, then moves to the next & repeats.
No intermediate Program is saved.
What is a Compiler?
Translates complete high-level program into machine language program. Complete translation before execution. Result can be executed repeatedly without further translation.
5 steps in the Program Development Cycle?
- Design the program
- Write the code
- Correct syntax errors
- Test the program
- Correct logic errors
Explain 2 ways to design/visualise a program:
Using Pseudocode (describing steps in plain speech as though to a person).
With a Flowchart diagram.
What is Pseudocode?
Pseudocode is a model computer program written in informal language that has no syntax rule
What 3 step process does a computer program usually follow?
Input | processing | output
Input: data received by program while running.
Processing: Perform operation on input (e.g. mathematical calculation).
Output: Produce desired information/response.
Instruct python to produce an output using the ____ function.
print(desired output)
How can I explain what’s going on in my code?
Comments are identified with a leading hash character. Python ignores everything to right of this on the line. Used to explain & identify components of the program for yourself & future users
Why use comments?
Comments (Python; indicated by leading hash character) are ignored by translator program; meant for humans. Offer explanation of parts of the program, enabling easier understanding, editing etc. For others and yourself, when you come back later.
How can I enter multi-line comments?
’’ Triple quotation marks:’’’
“”” These are used often to document the code; e.g. right at the top of a program describing functions, inputs & outputs”””
What’s a variable?
A value stored in the computers memory; that the program can store, update & retrieve.
variable = data… what is the equals sign here?
The assigment operator. It creates and/or updates the variable, named/addressed with vaue to its left, and assigning it the value to its right.
Python has strict variable naming rules:
Variable names:
- cannot be a Python keyword
- cannot contain spaces (use underscores for variable_name)
- first character must be a letter or an underscore
- otherwise contain only letters, digits, or underscores
- are case sensitive.
What variable data types have we learned?
int – for positive and negative integer numbers.
float – for positive and negative real numbers.
str – for character strings.
bool - boolean yes/no value
How does the interpreter assign data type for a numeric literal? (A number written in the program.)
Presence of a decimal point. ‘2.0’ = float. ‘2’ = integer.
Will this work?
….
if statement
print(‘string’)
…
No! Missing the colon after the if statement.
If statement:
Are these variables different?
number_input
Number_input
Yes, variable names are case sensitive.
What’s special about this variable?
NUMBER_INPUT
by convention, variables in all caps are ‘constants’; unchanged during program run. Reduces possible errors - enter value only once.
May be changed before running (e.g. reserve bank interest rate, needs updating in code when changed).
Shape meaning in flowchart:
Rectangle?
Process - an instruction to be carried out by the program.
Shape meaning in flowchart:
Parallelogram?
Input/output - represents entry by user or display of data by the program.
Shape meaning in flowchart:
Diamond?
Selection/Decision structure (if condition, then action…)`
Shape meaning in flowchart:
Oval?
Terminal - indicates start and end of a program.
What’s the difference between Iterations, Repetitions & Loops?
None. All interchangeable terms for ‘circular’ structures used to handle repetitive tasks in programs.
What do passwords have to do with loops?
Password entry is a data validation loop. While input != password, keep looping through ‘sorry, that wasn’t correct, try again’.