Python

What is an abstract class?

1.

An abstract class is the name for any class from which you can instantiate an object.

2.

Abstract classes must be redefined any time an object is instantiated from them.

3.

Abstract classes must inherit from concrete classes.

4.

An abstract class exists only so that other "concrete" classes can inherit from the abstract class.

Q 1 / 113

Python

What happens when you use the build-in function `any()` on a list?

**example** python if any([True, False, False, False]) == True: print('Yes, there is True') >>> Yes, there is True

1.

The `any()` function will randomly return any item from the list.

2.

The `any()` function returns True if any item in the list evaluates to True. Otherwise, it returns False.

3.

The `any()` function takes as arguments the list to check inside, and the item to check for. If "any" of the items in the list match the item to check for, the function returns True.

4.

The `any()` function returns a Boolean value that answers the question "Are there any items in this list?"

Q 2 / 113

Python

What data structure does a binary tree degenerate to if it isn't balanced properly?

1.

linked list

2.

queue

3.

set

4.

OrderedDict

Q 3 / 113

Python

What statement about static methods is true?

1.

Static methods are called static because they always return `None`.

2.

Static methods can be bound to either a class or an instance of a class.

3.

Static methods serve mostly as utility methods or helper methods, since they can't access or modify a class's state.

4.

Static methods can access and modify the state of a class or an instance of a class.

Q 4 / 113

Python

What are attributes?

**Explanation** Attributes defined under the class, arguments goes under the functions. arguments usually refer as parameter, whereas attributes are the constructor of the class or an instance of a class.

1.

Attributes are long-form version of an `if/else` statement, used when testing for equality between objects.

2.

Attributes are a way to hold data or describe a state for a class or an instance of a class.

3.

Attributes are strings that describe characteristics of a class.

4.

Function arguments are called "attributes" in the context of class methods and instance methods.

Q 5 / 113

Python

What is the term to describe this code?

`count, fruit, price = (2, 'apple', 3.5)`

1.

`tuple assignment`

2.

`tuple unpacking`

3.

`tuple matching`

4.

`tuple duplication`

Q 6 / 113

Python

What built-in list method would you use to remove items from a list?

**example** python my_list = [1,2,3] my_list.pop(0) my_list >>>[2,3]

1.

`.delete()` method

2.

`pop(my_list)`

3.

`del(my_list)`

4.

`.pop()` method

Q 7 / 113

Python

What is one of the most common use of Python's sys library?

1.

to capture command-line arguments given at a file's runtime

2.

to connect various systems, such as connecting a web front end, an API service, a database, and a mobile app

3.

to take a snapshot of all the packages and libraries in your virtual environment

4.

to scan the health of your Python ecosystem while inside a virtual environment

Q 8 / 113

Python

What is the runtime of accessing a value in a dictionary by using its key?

1.

O(n), also called linear time.

2.

O(log n), also called logarithmic time.

3.

O(n^2), also called quadratic time.

4.

O(1), also called constant time.

Q 9 / 113

Python

What is the correct syntax for defining a class called Game, if it inherits from a parent class called LogicGame?

**Explanation:** `The parent class which is inherited is passed as an argument to the child class. Therefore, here the first option is the right answer.`

1.

`class Game(LogicGame): pass`

2.

`def Game(LogicGame): pass`

3.

`def Game.LogicGame(): pass`

4.

`class Game.LogicGame(): pass`

Q 10 / 113

Python

What is the correct way to write a doctest?

python def sum(a, b): """ sum(4, 3) 7 sum(-4, 5) 1 """ return a + b python def sum(a, b): """ >>> sum(4, 3) 7 >>> sum(-4, 5) 1 """ return a + b python def sum(a, b): """ # >>> sum(4, 3) # 7 # >>> sum(-4, 5) # 1 """ return a + b python def sum(a, b): ### >>> sum(4, 3) 7 >>> sum(-4, 5) 1 ### return a + b **explanation** - use ''' to start the doc and add output of the cell after >>>

1.

A

2.

B

3.

C

4.

D

Q 11 / 113

Python

What built-in Python data type is commonly used to represent a stack?

`. You can only build a stack from scratch.`

1.

`set`

2.

`list`

3.

`None`

4.

`dictionary`

Q 12 / 113

Python

What would this expression return?

python college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior'] return list(enumerate(college_years, 2019))

1.

`[('Freshman', 2019), ('Sophomore', 2020), ('Junior', 2021), ('Senior', 2022)]`

2.

`[(2019, 2020, 2021, 2022), ('Freshman', 'Sophomore', 'Junior', 'Senior')]`

3.

`[('Freshman', 'Sophomore', 'Junior', 'Senior'), (2019, 2020, 2021, 2022)]`

4.

`[(2019, 'Freshman'), (2020, 'Sophomore'), (2021, 'Junior'), (2022, 'Senior')]`

Q 13 / 113

Python

What is the purpose of the "self" keyword when defining or calling instance methods?

**Simple example** python class my_secrets: def __init__(self, password): self.password = password pass instance = my_secrets('1234') instance.password >>>'1234'

1.

`self` means that no other arguments are required to be passed into the method.

2.

There is no real purpose for the `self` method; it's just historic computer science jargon that Python keeps to stay consistent with other programming languages.

3.

`self` refers to the instance whose method was called.

4.

`self` refers to the class that was inherited from to create the object using `self`.

Q 14 / 113

Python

Which of these is NOT a characteristic of namedtuples?

**We need to import it using**:`from collections import namedtuple`

1.

You can assign a name to each of the `namedtuple` members and refer to them that way, similarly to how you would access keys in `dictionary`.

2.

Each member of a namedtuple object can be indexed to directly, just like in a regular `tuple`.

3.

`namedtuples` are just as memory efficient as regular `tuples`.

4.

No import is needed to use `namedtuples` because they are available in the standard library.

Q 15 / 113

Python

What is an instance method?

1.

Instance methods can modify the state of an instance or the state of its parent class.

2.

Instance methods hold data related to the instance.

3.

An instance method is any class method that doesn't take any arguments.

4.

An instance method is a regular function that belongs to a class, but it must return `None`.

Q 16 / 113

Python

Which statement does NOT describe the object-oriented programming concept of encapsulation?

1.

It protects the data from outside interference.

2.

A parent class is encapsulated and no data from the parent class passes on to the child class.

3.

It keeps data and the methods that can manipulate that data in one place.

4.

It only allows the data to be changed by methods.

Q 17 / 113

Python

What is the purpose of an if/else statement?

1.

It tells the computer which chunk of code to run if the instructions you coded are incorrect.

2.

It runs one chunk of code if all the imports were successful, and another chunk of code if the imports were not successful.

3.

It executes one chunk of code if a condition is true, but a different chunk of code if the condition is false.

4.

It tells the computer which chunk of code to run if the is enough memory to handle it, and which chunk of code to run if there is not enough memory to handle it.

Q 18 / 113

Python

What built-in Python data type is best suited for implementing a queue?

1.

dictionary

2.

set

3.

None. You can only build a queue from scratch.

4.

list

Q 19 / 113

Python

What is the correct syntax for instantiating a new object of the type Game?

1.

`my_game = class.Game()`

2.

`my_game = class(Game)`

3.

`my_game = Game()`

4.

`my_game = Game.create()`

Q 20 / 113

Python

What does the built-in `map()` function do?

**Explanation:** - The synax for `map()` function is `list(map(function,iterable)`. the simple area finder using map would be like this python import math radius = [1,2,3] area = list(map(lambda x: round(math.pi*(x**2), 2), radius)) area >>> [3.14, 12.57, 28.27]

1.

It creates a path from multiple values in an iterable to a single value.

2.

It applies a function to each item in an iterable and returns the value of that function.

3.

It converts a complex value type into simpler value types.

4.

It creates a mapping between two different elements of different iterables.

Q 21 / 113

Python

If you don't explicitly return a value from a function, what happens?

1.

The function will return a RuntimeError if you don't return a value.

2.

If the return keyword is absent, the function will return `None`.

3.

If the return keyword is absent, the function will return `True`.

4.

The function will enter an infinite loop because it won't know when to stop executing its code.

Q 22 / 113

Python

What is the purpose of the `pass` statement in Python?

1.

It is used to skip the `yield` statement of a generator and return a value of None.

2.

It is a null operation used mainly as a placeholder in functions, classes, etc.

3.

It is used to pass control from one statement block to another.

4.

It is used to skip the rest of a `while` or `for loop` and return to the start of the loop.

Q 23 / 113

Python

What is the term used to describe items that may be passed into a function?

1.

arguments

2.

paradigms

3.

attributes

4.

decorators

Q 24 / 113

Python

Which collection type is used to associate values with unique keys?

1.

`slot`

2.

`dictionary`

3.

`queue`

4.

`sorted list`

Q 25 / 113

Python

When does a for loop stop iterating?

1.

when it encounters an infinite loop

2.

when it encounters an if/else statement that contains a break keyword

3.

when it has assessed each item in the iterable it is working on or a break keyword is encountered

4.

when the runtime for the loop exceeds O(n^2)

Q 26 / 113

Python

Assuming the node is in a singly linked list, what is the runtime complexity of searching for a specific node within a singly linked list?

1.

The runtime is O(n) because in the worst case, the node you are searching for is the last node, and every node in the linked list must be visited.

2.

The runtime is O(nk), with n representing the number of nodes and k representing the amount of time it takes to access each node in memory.

3.

The runtime cannot be determined unless you know how many nodes are in the singly linked list.

4.

The runtime is O(1) because you can index directly to a node in a singly linked list.

Q 27 / 113

Python

Given the following three list, how would you create a new list that matches the desired output printed below?

python fruits = ['Apples', 'Oranges', 'Bananas'] quantities = [5, 3, 4] prices = [1.50, 2.25, 0.89] #Desired output ('Oranges', 3, 2.25), ('Bananas', 4, 0.89)] python output = [] fruit_tuple_0 = (first[0], quantities[0], price[0]) output.append(fruit_tuple) fruit_tuple_1 = (first[1], quantities[1], price[1]) output.append(fruit_tuple) fruit_tuple_2 = (first[2], quantities[2], price[2]) output.append(fruit_tuple) return output python i = 0 output = [] for fruit in fruits: temp_qty = quantities[i] temp_price = prices[i] output.append((fruit, temp_qty, temp_price)) i += 1 return output python groceries = zip(fruits, quantities, prices) return groceries >>> [ ('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89) ] python i = 0 output = [] for fruit in fruits: for qty in quantities: for price in prices: output.append((fruit, qty, price)) i += 1 return output

1.

python fruits = ['Apples', 'Oranges', 'Bananas'] quantities = [5, 3, 4] prices = [1.50, 2.25, 0.89] #Desired output [('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89)]

2.

python output = [] fruit_tuple_0 = (first[0], quantities[0], price[0]) output.append(fruit_tuple) fruit_tuple_1 = (first[1], quantities[1], price[1]) output.append(fruit_tuple) fruit_tuple_2 = (first[2], quantities[2], price[2]) output.append(fruit_tuple) return output

3.

python i = 0 output = [] for fruit in fruits: temp_qty = quantities[i] temp_price = prices[i] output.append((fruit, temp_qty, temp_price)) i += 1 return output

4.

python groceries = zip(fruits, quantities, prices) return groceries >>> [ ('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89) ]

5.

python i = 0 output = [] for fruit in fruits: for qty in quantities: for price in prices: output.append((fruit, qty, price)) i += 1 return output

Q 28 / 113

Python

What happens when you use the built-in function all() on a list?

**Explaination** - `all()` returns true if all in the list are True, see example below python test = [True,False,False,False] if all(test) is True: print('Yeah all are True') else: print('There is an imposter') >>> There is an imposter

1.

The `all()` function returns a Boolean value that answers the question "Are all the items in this list the same?

2.

The `all()` function returns True if all the items in the list can be converted to strings. Otherwise, it returns False.

3.

The `all()` function will return all the values in the list.

4.

The `all()` function returns True if all items in the list evaluate to True. Otherwise, it returns False.

Q 29 / 113

Python

What is the correct syntax for calling an instance method on a class named Game?

_(Answer format may vary. Game and roll (or dice_roll) should each be called with no parameters.)_ python >>> dice = Game() >>> dice.roll() python >>> dice = Game(self) >>> dice.roll(self) python >>> dice = Game() >>> dice.roll(self) python >>> dice = Game(self) >>> dice.roll()

1.

python >>> dice = Game() >>> dice.roll()

2.

python >>> dice = Game(self) >>> dice.roll(self)

3.

python >>> dice = Game() >>> dice.roll(self)

4.

python >>> dice = Game(self) >>> dice.roll()

Q 30 / 113

Python

What is the algorithmic paradigm of quick sort?

1.

backtracking

2.

dynamic programming

3.

decrease and conquer

4.

divide and conquer

Q 31 / 113

Python

What is runtime complexity of the list's built-in `.append()` method?

1.

O(1), also called constant time

2.

O(log n), also called logarithmic time

3.

O(n^2), also called quadratic time

4.

O(n), also called linear time

Q 32 / 113

Python

What is key difference between a `set` and a `list`?

1.

A set is an ordered collection unique items. A list is an unordered collection of non-unique items.

2.

Elements can be retrieved from a list but they cannot be retrieved from a set.

3.

A set is an ordered collection of non-unique items. A list is an unordered collection of unique items.

4.

A set is an unordered collection unique items. A list is an ordered collection of non-unique items.

Q 33 / 113

Python

What is the definition of abstraction as applied to object-oriented Python?

1.

Abstraction means that a different style of code can be used, since many details are already known to the program behind the scenes.

2.

Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown.

3.

Abstraction means that the data and the functionality of a class are combined into one entity.

4.

Abstraction means that a class can inherit from more than one parent class.

Q 34 / 113

Python

What does this function print?

python def print_alpha_nums(abc_list, num_list): for char in abc_list: for num in num_list: print(char, num) return print_alpha_nums(['a', 'b', 'c'], [1, 2, 3]) python a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3 python python aaa bbb ccc 111 222 333 python a 1 2 3 b 1 2 3 c 1 2 3

1.

python a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3

2.

python ['a', 'b', 'c'], [1, 2, 3]

3.

python aaa bbb ccc 111 222 333

4.

python a 1 2 3 b 1 2 3 c 1 2 3

Q 35 / 113

Python

Correct representation of doctest for function in Python

python def sum(a, b): # a = 1 # b = 2 # sum(a, b) = 3 return a + b python def sum(a, b): """ a = 1 b = 2 sum(a, b) = 3 """ return a + b python def sum(a, b): """ >>> a = 1 >>> b = 2 >>> sum(a, b) 3 """ return a + b python def sum(a, b): ''' a = 1 b = 2 sum(a, b) = 3 ''' return a + b **Explanation:** Use """ to start and end the docstring and use >>> to represent the output. If you write this correctly you can also run the doctest using build-in doctest module

1.

python def sum(a, b): # a = 1 # b = 2 # sum(a, b) = 3 return a + b

2.

python def sum(a, b): """ a = 1 b = 2 sum(a, b) = 3 """ return a + b

3.

python def sum(a, b): """ >>> a = 1 >>> b = 2 >>> sum(a, b) 3 """ return a + b

4.

python def sum(a, b): ''' a = 1 b = 2 sum(a, b) = 3 ''' return a + b

Q 36 / 113

Python

Suppose a Game class inherits from two parent classes: BoardGame and LogicGame. Which statement is true about the methods of an object instantiated from the Game class?

1.

When instantiating an object, the object doesn't inherit any of the parent class's methods.

2.

When instantiating an object, the object will inherit the methods of whichever parent class has more methods.

3.

When instantiating an object, the programmer must specify which parent class to inherit methods from.

4.

An instance of the Game class will inherit whatever methods the BoardGame and LogicGame classes have.

Q 37 / 113

Python

What does calling namedtuple on a collection type return?

**Example** python import math radius = [1,2,3] area = list(map(lambda x: round(math.pi*(x**2), 2), radius)) area >>> [3.14, 12.57, 28.27]

1.

a generic object class with iterable parameter fields

2.

a generic object class with non-iterable named fields

3.

a tuple subclass with non-iterable parameter fields

4.

a tuple subclass with iterable named fields

Q 38 / 113

Python

What symbol(s) do you use to assess equality between two elements?

1.

`&&`

2.

`=`

3.

`==`

4.

`||`

Q 39 / 113

Python

Review the code below. What is the correct syntax for changing the price to 1.5?

python fruit_info = { 'fruit': 'apple', 'count': 2, 'price': 3.5 }

1.

`fruit_info ['price'

2.

`my_list [3.5

3.

`1.5 = fruit_info ['price]`

4.

`my_list['price'

Q 40 / 113

Python

What value would be returned by this check for equality?

`5 != 6` **Explanation** - `!=` is equivalent to **not equal to** in python

1.

`yes`

2.

`False`

3.

`True`

4.

`None`

Q 41 / 113

Python

What does a class's `init()` method do?

**Example:** python class test: def __init__(self): print('I came here without your permission lol') pass t1 = test() >>> 'I came here without your permission lol'

1.

The `__init__` method makes classes aware of each other if more than one class is defined in a single code file.

2.

The`__init__` method is included to preserve backwards compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.

3.

The `__init__` method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.

4.

The `__init__` method initializes any imports you may have included at the top of your file.

Q 42 / 113

Python

What is meant by the phrase "space complexity"?

1.

`How many microprocessors it would take to run your code in less than one second`

2.

`How many lines of code are in your code file`

3.

`The amount of space taken up in memory as a function of the input size`

4.

`How many copies of the code file could fit in 1 GB of memory`

Q 43 / 113

Python

What is the correct syntax for creating a variable that is bound to a dictionary?

1.

`fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}`

2.

`fruit_info =('fruit': 'apple', 'count': 2,'price': 3.5 ).dict()`

3.

`fruit_info = ['fruit': 'apple', 'count': 2,'price': 3.5 ].dict()`

4.

`fruit_info = to_dict('fruit': 'apple', 'count': 2, 'price': 3.5)`

Q 44 / 113

Python

What is the proper way to write a list comprehension that represents all the keys in this dictionary?

`fruits = {'Apples': 5, 'Oranges': 3, 'Bananas': 4}`

1.

`fruit_names = [x in fruits.keys() for x]`

2.

`fruit_names = for x in fruits.keys() *`

3.

`fruit_names = [x for x in fruits.keys()]`

4.

`fruit_names = x for x in fruits.keys()`

Q 45 / 113

Python

What is the purpose of the `self` keyword when defining or calling methods on an instance of an object?

**Explanation:** - Try running the example of the Q45 without passing `self` argument inside the `__init__`, you'll understand the reason. You'll get the error like this `__init__() takes 0 positional arguments but 1 was given`, this means that something is going inside even if haven't specified, which is instance itself.

1.

`self` refers to the class that was inherited from to create the object using `self`.

2.

There is no real purpose for the `self` method. It's just legacy computer science jargon that Python keeps to stay consistent with other programming languages.

3.

`self` means that no other arguments are required to be passed into the method.

4.

`self` refers to the instance whose method was called.

Q 46 / 113

Python

What statement about the class methods is true?

1.

A class method is a regular function that belongs to a class, but it must return None.

2.

A class method can modify the state of the class, but they can't directly modify the state of an instance that inherits from that class.

3.

A class method is similar to a regular function, but a class method doesn't take any arguments.

4.

A class method hold all of the data for a particular class.

Q 47 / 113

Python

What does it mean for a function to have linear runtime?

1.

You did not use very many advanced computer programming concepts in your code.

2.

The difficulty level your code is written at is not that high.

3.

It will take your program less than half a second to run.

4.

The amount of time it takes the function to complete grows linearly as the input size increases.

Q 48 / 113

Python

What is the proper way to define a function?

1.

`def getMaxNum(list_of_nums): # body of function goes here`

2.

`func get_max_num(list_of_nums): # body of function goes here`

3.

`func getMaxNum(list_of_nums): # body of function goes here`

4.

`def get_max_num(list_of_nums): # body of function goes here`

Q 49 / 113

Python

According to the PEP 8 coding style guidelines, how should constant values be named in Python?

1.

in camel case without using underscores to separate words -- e.g. `maxValue = 255`

2.

in lowercase with underscores to separate words -- e.g. `max_value = 255`

3.

in all caps with underscores separating words -- e.g. `MAX_VALUE = 255`

4.

in mixed case without using underscores to separate words -- e.g. `MaxValue = 255`

Q 50 / 113

Python

Describe the functionality of a deque.

**Explanation** - `deque` is used to create block chanin and in that there is _first in first out_ approch, which means the last element to enter will be the first to leave.

1.

A deque adds items to one side and remove items from the other side.

2.

A deque adds items to either or both sides, but only removes items from the top.

3.

A deque adds items at either or both ends, and remove items at either or both ends.

4.

A deque adds items only to the top, but remove from either or both sides.

Q 51 / 113

Python

What is the correct syntax for creating a variable that is bound to a set?

1.

`my_set = {0, 'apple', 3.5}`

2.

`my_set = to_set(0, 'apple', 3.5)`

3.

`my_set = (0, 'apple', 3.5).to_set()`

4.

`my_set = (0, 'apple', 3.5).set()`

Q 52 / 113

Python

What is the correct syntax for defining an `__init__()` method that takes no parameters?

python class __init__(self): pass python def __init__(): pass python class __init__(): pass python def __init__(self): pass

1.

python class __init__(self): pass

2.

python def __init__(): pass

3.

python class __init__(): pass

4.

python def __init__(self): pass

Q 53 / 113

Python

Which of the following is TRUE About how numeric data would be organised in a binary Search tree?

1.

For any given Node in a binary Search Tree, the child node to the left is less than the value of the given node and the child node to its right is greater than the given node.

2.

Binary Search Tree cannot be used to organize and search through numeric data, given the complication that arise with very deep trees.

3.

The top node of the binary search tree would be an arbitrary number. All the nodes to the left of the top node need to be less than the top node's number, but they don't need to ordered in any particular way.

4.

The smallest numeric value would go in the top most node. The next highest number would go in its left child node, the the next highest number after that would go in its right child node. This pattern would continue until all numeric values were in their own node.

Q 54 / 113

Python

Why would you use a decorator?

1.

A decorator is similar to a class and should be used if you are doing functional programming instead of object oriented programming.

2.

A decorator is a visual indicator to someone reading your code that a portion of your code is critical and should not be changed.

3.

You use the decorator to alter the functionality of a function without having to modify the functions code.

4.

An import statement is preceded by a decorator, python knows to import the most recent version of whatever package or library is being imported.

Q 55 / 113

Python

When would you use a for loop?

1.

Only in some situations, as loops are used only for certain type of programming.

2.

When you need to check every element in an iterable of known length.

3.

When you want to minimize the use of strings in your code.

4.

When you want to run code in one file for a function in another file.

Q 56 / 113

Python

What is the most self-descriptive way to define a function that calculates sales tax on a purchase?

python def tax(my_float): '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.''' pass python def tx(amt): '''Gets the tax on an amount.''' python def sales_tax(amount): '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.''' python def calculate_sales_tax(subtotal): pass

1.

python def tax(my_float): '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.''' pass

2.

python def tx(amt): '''Gets the tax on an amount.'''

3.

python def sales_tax(amount): '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''

4.

python def calculate_sales_tax(subtotal): pass

Q 57 / 113

Python

What would happen if you did not alter the state of the element that an algorithm is operating on recursively?

1.

You do not have to alter the state of the element the algorithm is recursing on.

2.

You would eventually get a KeyError when the recursive portion of the code ran out of items to recurse on.

3.

You would get a RuntimeError: maximum recursion depth exceeded.

4.

The function using recursion would return None.

Q 58 / 113

Python

What is the runtime complexity of searching for an item in a binary search tree?

1.

The runtime for searching in a binary search tree is O(1) because each node acts as a key, similar to a dictionary.

2.

The runtime for searching in a binary search tree is O(n!) because every node must be compared to every other node.

3.

The runtime for searching in a binary search tree is generally O(h), where h is the height of the tree.

4.

The runtime for searching in a binary search tree is O(n) because every node in the tree must be visited.

Q 59 / 113

Python

Why would you use `mixin`?

1.

You use a `mixin` to force a function to accept an argument at runtime even if the argument wasn't included in the function's definition.

2.

You use a `mixin` to allow a decorator to accept keyword arguments.

3.

You use a `mixin` to make sure that a class's attributes and methods don't interfere with global variables and functions.

4.

If you have many classes that all need to have the same functionality, you'd use a `mixin` to define that functionality.

Q 60 / 113

Python

What is the runtime complexity of adding an item to a stack and removing an item from a stack?

1.

Add items to a stack in O(1) time and remove items from a stack on O(n) time.

2.

Add items to a stack in O(1) time and remove items from a stack in O(1) time.

3.

Add items to a stack in O(n) time and remove items from a stack on O(1) time.

4.

Add items to a stack in O(n) time and remove items from a stack on O(n) time.

Q 61 / 113

Python

Which statement accurately describes how items are added to and removed from a stack?

**Explanation** Stack uses the _last in first out_ approach

1.

a stacks adds items to one side and removes items from the other side.

2.

a stacks adds items to the top and removes items from the top.

3.

a stacks adds items to the top and removes items from anywhere in the stack.

4.

a stacks adds items to either end and removes items from either end.

Q 62 / 113

Python

What is a base case in a recursive function?

1.

A base case is the condition that allows the algorithm to stop recursing. It is usually a problem that is small enough to solve directly.

2.

The base case is summary of the overall problem that needs to be solved.

3.

The base case is passed in as an argument to a function whose body makes use of recursion.

4.

The base case is similar to a base class, in that it can be inherited by another object.

Q 63 / 113

Python

Why is it considered good practice to open a file from within a Python script by using the `with` keyword?

1.

The `with` keyword lets you choose which application to open the file in.

2.

The `with` keyword acts like a `for` loop, and lets you access each line in the file one by one.

3.

There is no benefit to using the `with` keyword for opening a file in Python.

4.

When you open a file using the `with` keyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.

Q 64 / 113

Python

Why would you use a virtual environment?

1.

Virtual environments create a "bubble" around your project so that any libraries or packages you install within it don't affect your entire machine.

2.

Teams with remote employees use virtual environments so they can share code, do code reviews, and collaborate remotely.

3.

Virtual environments were common in Python 2 because they augmented missing features in the language. Virtual environments are not necessary in Python 3 due to advancements in the language.

4.

Virtual environments are tied to your GitHub or Bitbucket account, allowing you to access any of your repos virtually from any machine.

Q 65 / 113

Python

What is the correct way to run all the doctests in a given file from the command line?

1.

`python3 -m doctest <_filename_>`

2.

`python3 <_filename_>`

3.

`python3 <_filename_> rundoctests`

4.

`python3 doctest`

Q 66 / 113

Python

What is a lambda function ?

**Explanation:** `the lambda notation is basically an anonymous function that can take any number of arguments with only single expression (i.e, cannot be overloaded). It has been introducted in other programming languages, such as C++ and Java. The lambda notation allows programmers to "bypass" function declaration.`

1.

any function that makes use of scientific or mathematical constants, often represented by Greek letters in academic writing

2.

a function that get executed when decorators are used

3.

any function whose definition is contained within five lines of code or fewer

4.

a small, anonymous function that can take any number of arguments but has only expression to evaluate

Q 67 / 113

Python

What is the primary difference between lists and tuples?

1.

You can access a specifc element in a list by indexing to its position, but you cannot access a specific element in a tuple unless you iterate through the tuple

2.

Lists are mutable, meaning you can change the data that is inside them at any time. Tuples are immutable, meaning you cannot change the data that is inside them once you have created the tuple.

3.

Lists are immutable, meaning you cannot change the data that is inside them once you have created the list. Tuples are mutable, meaning you can change the data that is inside them at any time.

4.

Lists can hold several data types inside them at once, but tuples can only hold the same data type if multiple elements are present.

Q 68 / 113

Python

Which statement about static method is true?

1.

Static methods can be bound to either a class or an instance of a class.

2.

Static methods can access and modify the state of a class or an instance of a class.

3.

Static methods serve mostly as utility or helper methods, since they cannot access or modify a class's state.

4.

Static methods are called static because they always return None.

Q 69 / 113

Python

What does a generator return?

1.

None

2.

An iterable object

3.

A linked list data structure from a non-empty list

4.

All the keys of the given dictionary

Q 70 / 113

Python

What is the difference between class attributes and instance attributes?

1.

Instance attributes can be changed, but class attributes cannot be changed

2.

Class attributes are shared by all instances of the class. Instance attributes may be unique to just that instance

3.

There is no difference between class attributes and instance attributes

4.

Class attributes belong just to the class, not to instance of that class. Instance attributes are shared among all instances of a class

Q 71 / 113

Python

What is the correct syntax of creating an instance method?

python def get_next_card(): # method body goes here python def get_next_card(self): # method body goes here python def self.get_next_card(): # method body goes here python def self.get_next_card(self): # method body goes here

1.

python def get_next_card(): # method body goes here

2.

python def get_next_card(self): # method body goes here

3.

python def self.get_next_card(): # method body goes here

4.

python def self.get_next_card(self): # method body goes here

Q 72 / 113

Python

What is the correct way to call a function?

1.

get_max_num([57, 99, 31, 18])

2.

call.(get_max_num)

3.

def get_max_num([57, 99, 31, 18])

4.

call.get_max_num([57, 99, 31, 18])

Q 73 / 113

Python

How is comment created?

1.

`-- This is a comment`

2.

`# This is a comment`

3.

`/_ This is a comment _`

4.

`// This is a comment`

Q 74 / 113

Python

What is the correct syntax for replacing the string apple in the list with the string orange?

my_list = ['kiwi', 'apple', 'banana']

1.

`orange = my_list[1]`

2.

`my_list[1

3.

`my_list['orange'

4.

`my_list[1

Q 75 / 113

Python

What will happen if you use a while loop and forget to include logic that eventually causes the while loop to stop?

1.

Nothing will happen; your computer knows when to stop running the code in the while loop.

2.

You will get a KeyError.

3.

Your code will get stuck in an infinite loop.

4.

You will get a WhileLoopError.

Q 76 / 113

Python

Describe the functionality of a queue?

1.

A queue adds items to either end and removes items from either end.

2.

A queue adds items to the top and removes items from the top.

3.

A queue adds items to the top, and removes items from anywhere in, a list.

4.

A queue adds items to the top and removes items from anywhere in the queue.

Q 77 / 113

Python

Which choice is the most syntactically correct example of the conditional branching?

python num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") elif num_people > 4: print("There are some people in the pool.") else: print("There is no one in the pool.") python num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") if num_people > 4: print("There are some people in the pool.") else: print("There is no one in the pool.") python num_people = 5 if num_people > 10; print("There is a lot of people in the pool.") elif num_people > 4; print("There are some people in the pool.") else; print("There is no one in the pool.") python if num_people > 10; print("There is a lot of people in the pool.") if num_people > 4; print("There are some people in the pool.") else; print("There is no one in the pool.")

1.

python num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") elif num_people > 4: print("There are some people in the pool.") else: print("There is no one in the pool.")

2.

python num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") if num_people > 4: print("There are some people in the pool.") else: print("There is no one in the pool.")

3.

python num_people = 5 if num_people > 10; print("There is a lot of people in the pool.") elif num_people > 4; print("There are some people in the pool.") else; print("There is no one in the pool.")

4.

python if num_people > 10; print("There is a lot of people in the pool.") if num_people > 4; print("There are some people in the pool.") else; print("There is no one in the pool.")

Q 78 / 113

Python

How does `defaultdict` work?

1.

`defaultdict` will automatically create a dictionary for you that has keys which are the integers 0-10.

2.

`defaultdict` forces a dictionary to only accept keys that are of the types specified when you created the `defaultdict` (such as strings or integers).

3.

If you try to read from a `defaultdict` with a nonexistent key, a new default key-value pair will be created for you instead of throwing a `KeyError`.

4.

`defaultdict` stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.

Q 79 / 113

Python

What is the correct syntax for adding a key called `variety` to the `fruit_info` dictionary that has a value of `Red Delicious`?

1.

`fruit_info['variety'

2.

`fruit_info['variety'

3.

`red_delicious = fruit_info['variety']`

4.

`red_delicious == fruit_info['variety']`

Q 80 / 113

Python

When would you use a `while` loop?

**Simple Example** python i = 1 while i<6: print('Countdown:',i) i = i + 1

1.

when you want to minimize the use of strings in your code

2.

when you want to run code in one file while code in another file is also running

3.

when you want some code to continue running as long as some condition is true

4.

when you need to run two or more chunks of code at once within the same file

Q 81 / 113

Python

What is the correct syntax for defining an `__init__()` method that sets instance-specific attributes upon creation of a new class instance?

python def __init__(self, attr1, attr2): attr1 = attr1 attr2 = attr2 python def __init__(attr1, attr2): attr1 = attr1 attr2 = attr2 python def __init__(self, attr1, attr2): self.attr1 = attr1 self.attr2 = attr2 python def __init__(attr1, attr2): self.attr1 = attr1 self.attr2 = attr2 **Explanation**: When instantiating a new object from a given class, the `__init__()` method will take both `attr1` and `attr2`, and set its values to their corresponding object attribute, that's why the need of using `self.attr1 = attr1` instead of `attr1 = attr1`.

1.

python def __init__(self, attr1, attr2): attr1 = attr1 attr2 = attr2

2.

python def __init__(attr1, attr2): attr1 = attr1 attr2 = attr2

3.

python def __init__(self, attr1, attr2): self.attr1 = attr1 self.attr2 = attr2

4.

python def __init__(attr1, attr2): self.attr1 = attr1 self.attr2 = attr2

Q 82 / 113

Python

What would this recursive function print if it is called with no parameters?

python def count_recursive(n=1): if n > 3: return print(n) count_recursive(n + 1) python 1 1 2 2 3 3 python 3 2 1 python 3 3 2 2 1 1 python 1 2 3

1.

python 1 1 2 2 3 3

2.

python 3 2 1

3.

python 3 3 2 2 1 1

4.

python 1 2 3

Q 83 / 113

Python

In Python, when using sets, you use **_ to calculate the intersection between two sets and _** to calculate the union.

1.

`Intersect;union`

2.

|; &

3.

&; |

4.

&&; ||

Q 84 / 113

Python

What will this code fragment return?

python import numpy as np np.ones([1,2,3,4,5])

1.

It returns a 5x5 matric; each row will have the values 1,2,3,4,5.

2.

It returns an array with the values 1,2,3,4,5

3.

It returns five different square matrices filled with ones. The first is 1x1, the second 2x2, and so on to 5x5

4.

It returns a 5-dimensional array of size 1x2x3x4x5 filled with 1s.

Q 85 / 113

Python

You encounter a FileNotFoundException while using just the filename in the `open` function. What might be the easiest solution?

1.

Make sure the file is on the system PATH

2.

Create a symbolic link to allow better access to the file

3.

Copy the file to the same directory as where the script is running from

4.

Add the path to the file to the PYTHONPATH environment variable

Q 86 / 113

Python

what will this command return?

python {x for x in range(100) if x%3 == 0}

1.

a set of all the multiples of 3 less then 100

2.

a set of all the number from 0 to 100 multiplied by 3

3.

a list of all the multiples of 3 less then 100

4.

a set of all the multiples of 3 less then 100 excluding 0

Q 87 / 113

Python

What does the // operator in Python 3 allow you to do?

1.

Perform integer division

2.

Perform operations on exponents

3.

Find the remainder of a division operation

4.

Perform floating point division

Q 88 / 113

Python

This code provides the _ of the list of numbers

python num_list = [21,13,19,3,11,5,18] num_list.sort() num_list[len(num_list)//2]

1.

mean

2.

mode

3.

median

4.

average

Q 89 / 113

Python

What file is imported to use dates in python?

1.

datetime

2.

dateday

3.

daytime

4.

timedate

Q 90 / 113

Python

What is the correct syntax for defining a class called Game?

1.

def Game(): pass

2.

def Game: pass

3.

class Game: pass

4.

class Game(): pass

Q 91 / 113

Python

What does a class's init() method do?

1.

The **init** method makes classes aware of each other if more than one class is defined in a single code file.

2.

The **init** method is included to preserve backward compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.

3.

The **init** method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.

4.

The **init** method initializes any imports you may have included at the top of your file.

Q 92 / 113

Python

What is the correct syntax for calling an instance method on a class named Game?

1.

my_game = Game(self) self.my_game.roll_dice()

2.

my_game = Game() self.my_game.roll_dice()

3.

my_game = Game() my_game.roll_dice()

4.

my_game = Game(self) my_game.roll_dice(self)

Q 93 / 113

Python

What is the output of this code? (NumPy has been imported as np.)?

a = np.array([1,2,3,4]) print(a[[False, True, False, False]])

1.

{0,2}

2.

[2]

3.

{2}

4.

[0,2,0,0]

Q 94 / 113

Python

Suppose you have a string variable defined as y=”stuff;thing;junk;”. What would be the output from this code?

Z = y.split(‘;’) len(z) **Explanation**: y=”stuff;thing;junk” len(z) ==> 3 y=”stuff;thing;junk;” len(z) ==> 4

1.

17

2.

4

3.

0

4.

3

Q 95 / 113

Python

What is the output of this code?

num_list = [1,2,3,4,5] num_list.remove(2) print(num_list) **Explanation**: num_list = [1,2,3,4,5] num_list.pop(2) [1,2,4,5] num_list.remove(2) [1,3,4,5]

1.

[1,2,4,5]

2.

[1,3,4,5]

3.

[3,4,5]

4.

[1,2,3]

Q 96 / 113

Python

What is the correct syntax for creating an instance method?

1.

def get_next_card(): # method body goes here

2.

def self.get_next_card(): # method body goes here

3.

def get_next_card(self): # method body goes here

4.

def self.get_next_card(self): # method body goes here

Q 97 / 113

Python

Which command will create a list from 10 down to 1? Example:

1.

reversed(list(range(1,11)))

2.

list(reversed(range(1,10)))

3.

list(range(10,1,-1))

4.

list(reversed(range(1,11)))

Q 98 / 113

Python

Which fragment of code will print exactly the same output as this fragment?

import math print(math.pow(2,10)) # prints 2 elevated to the 10th power print(2^10) print(2**10) y = [x*2 for x in range(1,10)] print(y) y = 1 for i in range(1,10): y = y * 2 print(y)

1.

print(2^10)

2.

print(2**10)

3.

y = [x*2 for x in range(1,10)] print(y)

4.

y = 1 for i in range(1,10): y = y * 2 print(y)

Q 99 / 113

Python

Elements surrounded by [] are **_**, {} are **_**, and () are **_**.

1.

sets only; lists or dictionaries; tuples

2.

lists; sets only; tuples

3.

tuples; sets or lists; dictionaries

4.

lists; dictionaries or sets; tuples

Q 100 / 113

Python

What is the output of this code? (NumPy has been imported as np.)

table = np.array([ [1,3], [2,4]]) print(table.max(axis=1))

1.

`[2, 4]`

2.

`[3, 4]`

3.

`[4]`

4.

`[1,2]`

Q 101 / 113

Python

What will this code print?

number = 3 print (f"The number is {number}")

1.

`The number is 3`

2.

`the number is 3`

3.

`THE NUMBER IS 3`

4.

It throws a TypeError because the integer must be cast to a string.

Q 102 / 113

Python

Which syntax correctly creates a variable that is bound to a tuple?

1.

`my_tuple tup(2, 'apple', 3.5) %D`

2.

`my_tuple [2, 'apple', 3.5].tuple() %D`

3.

`my_tuple = (2, 'apple', 3.5)`

4.

`my_tuple = [2, 'apple', 3.5]`

Q 103 / 113

Python

Which mode is not a valid way to access a file from within a Python script?

1.

write('w')

2.

scan('s')

3.

append('a')

4.

read('r')

Q 104 / 113

Python

Suppose you have a variable named `vector` of type `np.array` with 10.000 elements. How can you turn `vector` into a variable named `matrix` with dimensions 100x100?: _[ANSWER NEEDED]_

**Example** python import numpy as np vector = np.random.rand(10000) matrix = a.reshape(100, 100) print(matrix.shape) (100, 100)

1.

matrix = matrix(vector,100,100)

2.

matrix = vector.to_matrix(100,100)

3.

matrix = (vector.shape = (100,100))

4.

matrix = vector.reshape(100,100)

Q 105 / 113

Python

NumPy allows you to multiply two arrays without a for loop. This is an example of _.

1.

vectorization

2.

attributions

3.

accelaration

4.

functional programming

Q 106 / 113

Python

What built-in Python data type can be used as a hash table?

1.

`set`

2.

`list`

3.

`tuple`

4.

`dictionary`

Q 107 / 113

Python

Which Python function allows you to execute Linux shell commands in Python?

1.

`sys.exc_info()`

2.

`os.system()`

3.

`os.getcwd()`

4.

`sys.executable`

Q 108 / 113

Python

Suppose you have the following code snippet and want to extract a list with only the letters. Which fragment of code will _not_ achieve that goal?

my_dictionary = { 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5 } letters = [] for letter in my_dictionary.values(): letters.append(letter) letters = my_dictionary.keys() letters = [letter for (letter, number) in my_dictionary.items()] letters4 = list(my_dictionary) **Explanation:** The first one (the correct option) returns the list of the values (the letters). The rest of the options return a list of the keys.

1.

letters = [] for letter in my_dictionary.values(): letters.append(letter)

2.

letters = my_dictionary.keys()

3.

letters = [letter for (letter, number) in my_dictionary.items()]

4.

letters4 = list(my_dictionary)

Q 109 / 113

Python

When an array is large, NumPy will not print the entire array when given the built-in `print` function. What function can you use within NumPy to force it to print the entire array?

1.

`set_printparams`

2.

`set_printoptions`

3.

`set_fullprint`

4.

`setp_printwhole`

Q 110 / 113

Python

When would you use a try/except block in code?

1.

You use `try/except` blocks when you want to run some code, but need a way to execute different code if an exception is raised.

2.

You use `try/except` blocks inside of unit tests so that the unit testes will always pass.

3.

You use `try/except` blocks so that you can demonstrate to your code reviewers that you tried a new approach, but if the new approach is not what they were looking for, they can leave comments under the `except` keyword.

4.

You use `try/except` blocks so that none of your functions or methods return `None`.

Q 111 / 113

Python

In Python, how can the compiler identify the inner block of a for loop?

1.

`because of the level of indentation after the for loop`

2.

`because of the end keyword at the end of the for loop`

3.

`because of the block is surrounded by brackets ({})`

4.

`because of the blank space at the end of the body of the for loop`

Q 112 / 113

Python

What Python mechanism is best suited for telling a user they are using a deprecated function

1.

sys.stdout

2.

traceback

3.

warnings

4.

exceptions

Q 113 / 113