Exam 2 Flashcards
(29 cards)
boolean value
two possible values (true or false)
the expression results in true or false
random module
random. random() - generate a random number between 0 and 1
random. randint(a,b)
if statement
one way if statement
sometimes called the if block
if-else statements
to way if statement because there are two sets of code only one of which will be executed
nested if statement
nested is like russian nesting dolls
if statement within an if statement
if-else-if statement
multiway (3 or greater)
if, elif, else:
common errors dealing with the if-else statements
wrong indentation
misplaced else - (especially dealing with nested if statements)
using the wrong operator - (off by one error by using > instead of >=)
missing else
logical operators
not, and, or
Order of Operations
() \+, - Unary ** Not *, /, //, % \+, - binary , >= ==, != and or assignment operators and augmented operators
while loops
while count < 100:
print(“This is a message”)
count += 1
common errors of while loops
infinite loops - (a loop that cannot end)
off by one error
loop control
counter
sentinel value
user control
for sequence
for in
range function
range(0, 100, 2)
Break command
break will exit a loop
continue command
exits the current iteration and continues the loop
stack and heap
used to organize programs while it’s executing
stack stores
variables
parameters
references - an address that says where something is located
how stack works
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
heap stores
objects
void functions
returns none
none can be used as an object
positional parameters
needs to come in order
needs to match the same number of formal parameters
needs to match type
keyword parameters
can be used out of order the specific parameter is specified
scope
places where the identifier can be used