Python Final Exam Flashcards

(62 cards)

1
Q

Program

A

sequence of instructions that specifies how to perform a computation

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

Computation

A

mathematical computation -> data processing, aka software

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

Hardware

A

physical parts that make up a computer

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

Typical hardware components

A

Central processing unit (CPU)
* Main memory (RAM)
* Secondary storage devices (HD)
* Input and output devices

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

Application software

A

Programs that make computer useful for
business and users
* Word
* Excel
* Photoshop
* Outlook
* Chrome
* iTunes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

System Software

A

Operating system
* Controls hardware
* Windows, MacOS, Linux, IOS, Android
Utilities
* Enhance or protects the computer
* Anti-virus, 7-zip, Parallels
Software development tools
* Create and modify software
* IDLE, Visual Studio, IntelliJ IDEA

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Low-level language

A

Close in nature to machine language
* Computer architecture specific. Not portable.

FORTRAN, COBOL, and C

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

High-level language

A

Allows simple creation of powerful and complex programs
* Agnostic to the computer architecture. Portable code.

Python, PHP, Java, C++, Ruby.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What types of processes do we have?

A

Math, conditions, repetition

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

Algorithm

A

set of step-by-step instructions that detail a process or
computation

(set of logical, well-defined rules or procedures for efficiently and
accurately solving a problem)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Pseudocode

A

informal high-level description of the structure of an
algorithm
* Written in a combination of natural language and programming
language constructs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Flowchart elements

A

terminal symbol = oval
processing symbol = rectangle
decision symbol = diamond
input/output = slanted rectangle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Python Advantages

A

High-level language
Extensible (lots of packages)
Versatile
Emphasis on style & readability
No semicolons/brackets –> mainly identation
interpreted NOT compiled (translate on the fly)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Difference Interactive mode versus Python scripts

A

Interactive mode = “console”, won’t save
Python script saves code, end in .py, can be run from IDLE with run button

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

IDLE

A

Integrated Development Program
Single program that provides tools to write, execute and test a program

Has interactive and scripting mode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Function

A

prewritten code that performs a “blackbox” operation (e.g. print, max etc.)

Group of statements that exist within in a larger program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Argument

A

any data that is passed to a function, e.g. “Hello again”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Default type for input

A

Str

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Variable

A

letter or word(s) that represents data stored in
the computer’s memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

//

A

Floor division, divides two numbers and then returns the lower integer

Example

7//2 = 3
(7 divided by 2 is 3.5, and then rounded down)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

%

A

Modulo - retains remainder

For example

7 % 2 = 1
(because 7 divided by 2 is 3 with a remainder of 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

format function

A

.2f –> print(f” {number.2f}”)
,.2f –> comma and two decimal places
.0% –> percentage rather than decimal
,d –> adds commas for whole integers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

end and sep arguments. Give an example

A

print(number sep=”___”)
print(number end=”___”)
\n = new line
\t = insert tab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Decision Structure

A

execute certain statements
only under certain circumstances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Conditional execution
execute statement only when the condition is true. Simplest form of Decision.
26
Condition Control (while loop)
Number of loops/iterations is unknown, Boolean expression usually exits the loop
27
Count controlled (for)
Based on a counter, number of loops is known
28
Nested loops
Inner cycle cycles through each iteration for each outer loop inner loop iterates multiple times (faster) than outer loop iterations = inner loop * outer loop
29
How to change items of a list?
a.append("new word") a.pop() --> deletes last item a[1] --> choose the index 1 a[4,6] --> selects index 4 and 5 a.insert(5, "banana") --> inserts banana at index 5 a.remove ("banana") --> removes all values with banana
30
What can control structure be divided in?
sequence, selection, and iteration.
31
Control structure
logical design that controls the order in which a set of statements execute
32
What are short-circuit evaluators?
logical operator that evaluates its operands from left to right and stops as soon as the result of the entire expression is determined The two existing one's in Python: And/or
33
Modularized program
Each task within the program is a function of its own
34
Benefits of modularized program
simpler use, better testing and debugging, faster development, code can be reused
35
Void function
executes a statement (e.g. prints a statement)
36
Value-returning function
executes a statement and then returns a value back (e.g. input, integer, float function etc)
37
Syntax void function
def function_name(): statement or def main(): function1() function2()
38
top-down design
technique to break down algorithm into functions through decomposition (through hierarchy)
39
Syntax value-returning function
def function_name(parameter1, parameter2): sum = parameter1+parameter2 return sum
40
Final Parameter
local variable that receives an argument
41
list
collection of items within an object, mutable
42
element
an item in a list
43
Syntax list
list1 = []
44
tuple
similar to list, but immutable (no insert or append)
45
enumerate function
adds counter to sequence listb = list(enumerate(lista)
46
slice syntac
lista[start:stop:step]
47
"in" operator in list
if x in lista:
48
list methods
append(item) index(item) insert (index, item) sort() for n in list:
49
average of a list
calculate total and divide by len(list)
50
2-dimensional lists
nested lists, rows and columns, a = [[a,b,c], [1,2,3]] indexed by two indeces e.g. [2][2] = 3
51
What does \ do in a string?
allows to break a statement into multiple line (similar to \n or \t)
52
Can strings be indexed?
Yes
53
Strings mutable or immutable?
Immutable, but can slice strings
54
Dictionaries
store collection of data with key and value
55
Syntax dictionary
dictionary = {k1:v1, k2:v2} or dict() function on a list
56
Advantages dictionaries
keys must be unique, very fast
57
How to retrieve values in dictionaries?
Use key, e.g. dictionary[key]
58
Get method for dictionaries
dictionary.get(key, default) --> if key does not exist a default value is returned
59
Iterate through dictionary
for key in dictionary: print(key) #prints the key print(dictionary[key]) #prints the value
60
Set
object that stores a collection, all items must be unique
61
Syntax Set
set1 = {} (but not key-value pairs) or set() function
62
open file syntax
file_name = open(filename, mode)