2.2 Flashcards
What is a variable?
- Value stored in memory that can change while the program is running
What is a constant?
- Value that does not change while the program is running
- Assigned when the program is designed
What is assignment?
- Giving a variable/constant a value
What is casting?
- Converting a variable from one data type to another
- integer/character/string/float/boolean
What is an input?
- Value read from an input device (e.g. keyboard)
What is an output?
- Data generated by the computer
- Displayed to the user
What does ** mean?
- Exponential
What does % mean?
- Modulus (remainder)
What does // mean?
- Quotient
What are the 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?
- Softwares receive data in a format they are expecting
- Manipulation of data
What are the 3 stages to writing 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()
What are the 3 stages to reading data from a file?
- variable = open(‘filename.txt’, ‘r’) to read
- variable2 = variable.readline()
- print(variable2)
- To read next line, just do another variable and do variable.readline() again
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
What are the advantages of subroutines?
- 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)
- Good programming technique
What is a record?
- Collection of related data items for one entity
(could be different data types)
What are records stored in text files?
- 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
What are records stored in arrays/lists?
- 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
What is the difference between an array and list?
- Array: static data structure (1D)
- List: dynamic data structure (2D)
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
What are the advantages of local variables?
- 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