CS Midterm 2
40 flashcards · Computer Science · by Elsa Schutfort
Best test to see if a boolean variable is true (Boolean variable isDone)
if isDone
A code that displays "Cannot get a driver's license" if age is less than 16
if age < 16
A code that displays "Can get a driver's license" if age is 16 and up
if age >= 16 else elif age >= 16
What the result of "True or True and False"
True
What the result of "True or False and False"
False
If func1() returns False when would func2() not be called (Boolean values)
func1() and func2()
Do if-else block have to end with an else?
No
What equivalent to if number % 2 == 0: even = True else: even = False
even = number % 2 == 0
What operator results in a Boolean value that is opposite of its operand? (operand is True and results in a False)
not
What range returns 0, 1, 2, 3, 4, 5
range(0, 6)
How many times is the print statement executed? for I in range(1,4): for j in range(i): print(I*j)
6
Will this program terminate and why? value = 10 while True: if value < 8: break value = value - 2
Yes, value is subtracted by 2 so its not bigger than 8
What does break terminate?
the entire loop
What does continue terminate?
only the current iteration of the loop
Is the body of a while loop guaranteed to execute at least one time?
No
Define iteration
the term for a single execution of a loop
What are the possible values of random.randint(0,100)
0 through 100
Define sentinel value
denotes the end of a data set but not part of the data
What is a step in a range?
The step is each increment it goes up by
define Formal Parameters
the name you use to refer to the actual parameter
Formal Parameters syntax
function(formal parameters)
define Actual Parameters
values that are passed to a function when it is invoked
Actual Parameters syntax
function(formal) code function(actual)
define Stack and Heap
used to organize function calls in a computer
Every time a function is called, data for the function placed on top of the
stack
Keywords example
formalParameter=value
Three main purposes of using functions
Reuse the same code, organize code, and make code simpler
Are return statements are required for functions?
no
define Arguments
another term for parameters of a function when it is called
keyword when defining a function
def function():
How do you call a function that has default arguments?
What is the name of the part of memory that stores objects when a function is called?
heap
Where are default arguments specified for a function?
as a formal parameter
When are positional actual parameters used?
when a function is called with parameters that do not include any keywords.
Importing a function in a module
from module import function
define local variable
a variable that is created inside a function
define global variable
a variable that are created outside of a function
define immutable
a object is immutable when the value can't be changed over time
immutable examples
numbers and strings
define Activation Record
stores parameters and local variables and is part of the program execution management when a function is called