Exam 2 Flashcards

(29 cards)

1
Q

boolean value

A

two possible values (true or false)

the expression results in true or false

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

random module

A

random. random() - generate a random number between 0 and 1

random. randint(a,b)

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

if statement

A

one way if statement

sometimes called the if block

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

if-else statements

A

to way if statement because there are two sets of code only one of which will be executed

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

nested if statement

A

nested is like russian nesting dolls

if statement within an if statement

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

if-else-if statement

A

multiway (3 or greater)

if, elif, else:

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

common errors dealing with the if-else statements

A

wrong indentation
misplaced else - (especially dealing with nested if statements)
using the wrong operator - (off by one error by using > instead of >=)
missing else

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

logical operators

A

not, and, or

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

Order of Operations

A
()
\+, - Unary
**
Not
*, /, //, %
\+, - binary
, >=
==, !=
and
or
assignment operators and augmented operators
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

while loops

A

while count < 100:
print(“This is a message”)
count += 1

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

common errors of while loops

A

infinite loops - (a loop that cannot end)

off by one error

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

loop control

A

counter
sentinel value
user control

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

for sequence

A

for in

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

range function

A

range(0, 100, 2)

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

Break command

A

break will exit a loop

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

continue command

A

exits the current iteration and continues the loop

17
Q

stack and heap

A

used to organize programs while it’s executing

18
Q

stack stores

A

variables
parameters
references - an address that says where something is located

19
Q

how stack works

A

a function is pushed onto the stack and taken off when it’s finished
activation records are stacked on top of each other
only the top can be removed

20
Q

heap stores

21
Q

void functions

A

returns none

none can be used as an object

22
Q

positional parameters

A

needs to come in order
needs to match the same number of formal parameters
needs to match type

23
Q

keyword parameters

A

can be used out of order the specific parameter is specified

24
Q

scope

A

places where the identifier can be used

25
global variable
``` not declared in a function only accessible in the module or file ```
26
local variable
is declared in a function | scope is the function
27
Object Oriented Programming (OOP)
we use objects to reuse, organize, and simplify code
28
method
``` function that is part of an object the data is already present in the object ```
29
function
the data needs to be entered as a parameter