Which would be the base case in a recursive solution to the problem of finding the
factorial of a number. Recall that the factorial of a non-negative whole number is defined
as n! where:
If n = 0, then n! = 1
If n > 0, then n! = 1 x 2 x 3 x ... x n - ANSW n = 0
The os Module's remove and rename functions delete a file and specify a new name for
a file, respectively. - ANSW True
__________ has the ability to define a method in a subclass and then define a method
with the same name in a superclass. - ANSW Polymorphism
What will the following program display?
def main():my_string = 'One, two, three, four'
word_list = my_string.split()
print(word_list)
main() - ANSW ['One,', 'two,', 'three,', 'four']
Which would you use to delete an existing key-value pair from a dictionary? - ANSW
del
A function is called from the main function for the first time and then calls itself seven
times. What is the depth of recursion? - ANSW 7
What will the following program display?
def main():print(test2(18, 5))def test2(x, y):if x < y:return -5else:return (test2(x-y, y+5) +
6)main() - ANSW 7
The base case is the case in which the problem can be solved without - ANSW
recursion
What is the number of the first index in a dictionary? - ANSW Dictionaries are not
indexed by number.
Converting objects to JSON text format known as serializing - ANSW True
If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError
exception is raised. - ANSW True
What will the following program display?
class Test:
def __init__(self):
, self.num1 = 0class
Derived_Test(Test):
def __init__(self):
self.num2 = 1def
main():
show = Derived_Test()
print(show.num1,show.num2)
main() - ANSW Error because class Derived_Test inherits Test but variable num1 isn't
inherited
Combining data and code in a single object is known as - ANSW encapsulation
Which of the following will create an object, worker_joey, of the Worker class? - ANSW
worker_joey = Worker()
Invalid indexes do not cause slicing expressions to raise an exception - ANSW
Question options:
True
A mutator method has no control over the way that a class's data attributes are
modified. - ANSW False
In a UML diagram the first section holds the list of the class's methods. - ANSW False
What will be displayed after the following code executes?
mystr = 'yes'
yourstr = 'no'
mystr += yourstr * 2
print(mystr) - ANSW yesnono
If the start index is __________ the end index, the slicing expression will return an
empty string. - ANSW greater than
What type of method provides a safe way for code outside a class to retrieve the values
of attributes, without exposing the attributes in a way that could allow them to be
changed by code outside the method? - ANSW accessor
When an object is passed as an argument, __________ is passed into the parameter
variable. - ANSW a reference to the object
Which section in the UML holds the list of the class's methods? - ANSW third section
What is the correct structure to create a dictionary of months where each month will be
accessed by its month number (for example, January is month 1, April is month 4)? -
ANSW { 1 : 'January', 2 : 'February', ... 12 : 'December' }