Python Final Exam Flashcards

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
Q

Conditional execution

A

execute statement only when the condition is
true. Simplest form of Decision.

26
Q

Condition Control (while loop)

A

Number of loops/iterations is unknown, Boolean expression usually exits the loop

27
Q

Count controlled (for)

A

Based on a counter, number of loops is known

28
Q

Nested loops

A

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
Q

How to change items of a list?

A

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
Q

What can control structure be divided in?

A

sequence, selection, and iteration.

31
Q

Control structure

A

logical design that controls the order in which a set of statements execute

32
Q

What are short-circuit evaluators?

A

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
Q

Modularized program

A

Each task within the program is a function of its own

34
Q

Benefits of modularized program

A

simpler use, better testing and debugging, faster development, code can be reused

35
Q

Void function

A

executes a statement (e.g. prints a statement)

36
Q

Value-returning function

A

executes a statement and then returns a value back (e.g. input, integer, float function etc)

37
Q

Syntax void function

A

def function_name():
statement

or

def main():
function1()
function2()

38
Q

top-down design

A

technique to break down algorithm into functions through decomposition (through hierarchy)

39
Q

Syntax value-returning function

A

def function_name(parameter1, parameter2):
sum = parameter1+parameter2
return sum

40
Q

Final Parameter

A

local variable that receives an argument

41
Q

list

A

collection of items within an object, mutable

42
Q

element

A

an item in a list

43
Q

Syntax list

A

list1 = []

44
Q

tuple

A

similar to list, but immutable (no insert or append)

45
Q

enumerate function

A

adds counter to sequence

listb = list(enumerate(lista)

46
Q

slice syntac

A

lista[start:stop:step]

47
Q

“in” operator in list

A

if x in lista:

48
Q

list methods

A

append(item)
index(item)
insert (index, item)
sort()
for n in list:

49
Q

average of a list

A

calculate total and divide by len(list)

50
Q

2-dimensional lists

A

nested lists, rows and columns, a = [[a,b,c], [1,2,3]]
indexed by two indeces e.g. [2][2] = 3

51
Q

What does \ do in a string?

A

allows to break a statement into multiple line (similar to \n or \t)

52
Q

Can strings be indexed?

A

Yes

53
Q

Strings mutable or immutable?

A

Immutable, but can slice strings

54
Q

Dictionaries

A

store collection of data with key and value

55
Q

Syntax dictionary

A

dictionary = {k1:v1, k2:v2} or dict() function on a list

56
Q

Advantages dictionaries

A

keys must be unique, very fast

57
Q

How to retrieve values in dictionaries?

A

Use key, e.g. dictionary[key]

58
Q

Get method for dictionaries

A

dictionary.get(key, default) –> if key does not exist a default value is returned

59
Q

Iterate through dictionary

A

for key in dictionary:
print(key) #prints the key
print(dictionary[key]) #prints the value

60
Q

Set

A

object that stores a collection, all items must be unique

61
Q

Syntax Set

A

set1 = {} (but not key-value pairs) or set() function

62
Q

open file syntax

A

file_name = open(filename, mode)