2.2 Flashcards
Variable
Value stored in memory that can change while the program is running
Constant
Value that does not change while the program is running, assigned when the program is designed
Assignment
Giving a variable/constant a value
Casting
- Converting a variable from one data type to another
- integer/character/string/float/boolean
Input
Value read from an input device (e.g. keyboard)
Output (2)
- Data generated by the computer
- Displayed to the user
**
Exponential
%
Modulus (remainder)
//
Quotient
Boolean Operators
- AND: both must be true (D logic gate with two inputs one output)
- OR: either must be true (fish/kite logic gate with two inputs one output)
- NOT: false (triangle with tip pointing right at a small dot with one input one output)
Why is casting necessary? (2)
- Softwares receive data in a format they are expecting
- Manipulation of data
3 stages to write data to a file
- variable = open(‘filename.txt’, ‘a’) to append (OR to write do ‘w’)
- variable.writeLines
- \n = enter a new line
- variable.close()
3 stages to read data in a file
- variable = open(‘filename.txt’, ‘r’) to read
- variable2 = variable.readline()
- print(variable2)
Why do you need to close a file?
- Releases the file handle and breaks the connection between it and program
- variable.close()
What do you have to do once you have written to a file but want to read it (or vice versa)?
- variable = open(‘filename.txt’, ‘r’) to read
- variable = open(‘filename.txt’, ‘a’) to append (OR to write do ‘w’)
- MUST do before cause that is just file handling rule
SQL Commands
- SELECT: field to be returned (* = all)
- FROM: which file
- WHERE: certain condition (LIKE = wildcard)
- ORDER BY: ASC or DESC
Explain the two main types of sub programs
- Procedures: carry out a task and provide structure to code (basically main.py)
- Functions: carry out a task and return a value, creating reusable program components
Advantages of Using Sub Programs (3)
- Easier to write entire program (many can work on large program at the same time, cutting down development time)
- Easier to debug (maintainability: can be tested separately)
- Reusable components (could be gathered into library for use over multiple programs)
What is a record?
- Collection of related data items
(could be different data types)
Records stored in text files… (5)
- Stored on secondary storage
- Used to store data when the application if closed
- Each entry is on a new line
- May require linear search to find data
- Structure text files (e.g. CSV) can be used to exchange stored data between applications
Records stored in arrays and lists… (5)
- Stored in main memory (RAM)
- Used to store data when program is running
- Single/multi-dimensional
- Indexes refer to data items
- Efficient algorithms are used to find data
Array (5)
- Thought of like a variable which can contain more than one data item
- Allocating a contiguous part of memory to store data
- Has same data type
- Visualise as a column/table (two dimension)
- Indexes start at 0
What are the three basic programming constructs?
- Sequence: executing one instruction after another, one by one
- Selection: a program branch depending on a condition (IF)
- Iteration: repeating code in a loop (counter (FOR)/condition (WHILE)) until a condition has been satisfied
Advantages of local variables (2)
- Self-contained within subroutine, can be used without variable names conflicting with those use in main (if a local and global variable have the same name, the local variable takes priority within the function
- Memory efficient: memory space is created when the subroutine is executing, it will be released when the execution is finished