2.2 Flashcards

1
Q

What is a variable?

A
  • Value stored in memory that can change while the program is running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a constant?

A
  • Value that does not change while the program is running
  • Assigned when the program is designed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is assignment?

A
  • Giving a variable/constant a value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is casting?

A
  • Converting a variable from one data type to another
  • integer/character/string/float/boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an input?

A
  • Value read from an input device (e.g. keyboard)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an output?

A
  • Data generated by the computer
  • Displayed to the user
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ** mean?

A
  • Exponential
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does % mean?

A
  • Modulus (remainder)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does // mean?

A
  • Quotient
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the boolean operators?

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is casting necessary?

A
  • Softwares receive data in a format they are expecting
  • Manipulation of data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 3 stages to writing data to a file?

A
  • variable = open(‘filename.txt’, ‘a’) to append (OR to write do ‘w’)
  • variable.writeLines
  • \n = enter a new line
  • variable.close()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the 3 stages to reading data from a file?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why do you need to close a file?

A
  • Releases the file handle and breaks the connection between it and program
  • variable.close()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do you have to do once you have written to a file but want to read it (or vice versa)?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

SQL Commands

A
  • SELECT: field to be returned (* = all)
  • FROM: which file
  • WHERE: certain condition (LIKE = wildcard)
  • ORDER BY: ASC or DESC
17
Q

Explain the two main types of sub programs

A
  • 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
18
Q

What are the advantages of subroutines?

A
  • 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
19
Q

What is a record?

A
  • Collection of related data items for one entity
    (could be different data types)
20
Q

What are records stored in text files?

A
  • 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
21
Q

What are records stored in arrays/lists?

A
  • 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
22
Q

What is the difference between an array and list?

A
  • Array: static data structure (1D)
  • List: dynamic data structure (2D)
23
Q

What are the three basic programming constructs?

A
  • 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
24
Q

What are the advantages of local variables?

A
  • 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