Python-Quiz MD
Python-Quiz MD
- [ ] An abstract class is the name for any class from which you can instantiate an object.
- [ ] Abstract classes must be redefined any time an object is instantiated from them.
- [ ] Abstract classes must inherit from concrete classes.
- [x] An abstract class exists only so that other "concrete" classes can inherit from the abstract
class.
[reference](https://www.geeksforgeeks.org/abstract-classes-in-python/)
#### Q2. What happens when you use the built-in function `any()` on a list?
- [ ] The `any()` function will randomly return any item from the list.
- [x] The `any()` function returns True if any item in the list evaluates to True. Otherwise, it
returns False.
- [ ] 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.
- [ ] The `any()` function returns a Boolean value that answers the question "Are there any items
in this list?"
**example**
```python
if any([True, False, False, False]) == True:
print('Yes, there is True')
>>> 'Yes, there is True'
```
#### Q3. What data structure does a binary tree degenerate to if it isn't balanced properly?
[reference](https://www.scaler.com/topics/linked-list/)
- [ ] Static methods are called static because they always return `None`.
- [ ] Static methods can be bound to either a class or an instance of a class.
- [x] Static methods serve mostly as utility methods or helper methods since they can't access or
modify a class's state.
- [ ] Static methods can access and modify the state of a class or an instance of a class.
[reference](https://www.geeksforgeeks.org/class-method-vs-static-method-python)
- [ ] Attributes are long-form versions of an `if/else` statement, used when testing for equality
between objects.
- [x] Attributes are a way to hold data or describe a state for a class or an instance of a class.
- [ ] Attributes are strings that describe characteristics of a class.
- [ ] Function arguments are called "attributes" in the context of class methods and instance
methods.
**Explanation:** Attributes are defined under the class, and arguments go under the functions.
arguments usually refer to parameters, whereas attributes are the constructors of the class or an
instance of a class.
1 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] Tuple assignment.
- [x] Tuple unpacking.
- [ ] Tuple matching.
- [ ] Tuple duplication.
[Reference](https://www.w3schools.com/python/python_tuples_unpack.asp)
#### Q7. What built-in list method would you use to remove items from a list?
- [ ] `.delete()` method
- [ ] `pop(my_list)`
- [ ] `del(my_list)`
- [x] `.pop()` method
[Reference](https://www.w3schools.com/python/ref_list_pop.asp)
**example**
```python
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
```
#### Q8. What is one of the most common uses of Python's `sys` library?
[reference](https://docs.python.org/3/library/sys.html)
#### Q9. What is the runtime of accessing a value in a dictionary by using its key?
#### Q10. 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.`
- [ ] A
2 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
def sum(a, b):
"""
sum(4, 3)
7
sum(-4, 5)
1
"""
return a + b
```
- [x] B
```python
def sum(a, b):
"""
>>> sum(4, 3)
7
>>> sum(-4, 5)
1
"""
return a + b
```
- [ ] C
```python
def sum(a, b):
"""
# >>> sum(4, 3)
# 7
# >>> sum(-4, 5)
# 1
"""
return a + b
```
- [ ] D
```python
def sum(a, b):
###
>>> sum(4, 3)
7
>>> sum(-4, 5)
1
###
return a + b
```
**Explanation:** Use `'''` to start the doc and add the output of the cell after `>>>`
#### Q12. What built-in Python data type is commonly used to represent a stack?
- [ ] `set`
- [x] `list`
- [ ] `None`
- [ ] `dictionary`
3 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
```
#### Q14. What is the purpose of the "self" keyword when defining or calling instance methods?
- [ ] `self` means that no other arguments are required to be passed into the method.
- [ ] 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.
- [x] `self` refers to the instance whose method was called.
- [ ] `self` refers to the class that was inherited from to create the object using `self`.
[Reference](https://www.geeksforgeeks.org/self-in-python-class/)
**Simple example**
```python
class my_secrets:
def __init__(self, password):
self.password = password
pass
instance = my_secrets('1234')
instance.password
>>>'1234'
```
- [ ] 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`.
- [ ] Each member of a namedtuple object can be indexed directly, just like in a regular `tuple`.
- [ ] `namedtuples` are just as memory efficient as regular `tuples`.
- [x] No import is needed to use `namedtuples` because they are available in the standard library.
- [x] Instance methods can modify the state of an instance or the state of its parent class.
- [ ] Instance methods hold data related to the instance.
- [ ] An instance method is any class method that doesn't take any arguments.
- [ ] An instance method is a regular function that belongs to a class, but it must return `None`.
#### Q17. Which statement does NOT describe the object-oriented programming concept of
encapsulation?
4 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[Reference](https://www.scaler.com/topics/python/encapsulation-in-python/)
- [ ] It tells the computer which chunk of code to run if the instructions you coded are
incorrect.
- [ ] It runs one chunk of code if all the imports were successful, and another chunk of code if
the imports were not successful.
- [x] It executes one chunk of code if a condition is true, but a different chunk of code if the
condition is false.
- [ ] 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.
[Reference](https://www.scaler.com/topics/python/python-if-else-statement/)
#### Q19. What built-in Python data type is best suited for implementing a queue?
- [ ] dictionary
- [ ] set
- [ ] None. You can only build a queue from scratch.
- [x] list
#### Q20. What is the correct syntax for instantiating a new object of the type Game?
- [ ] `my_game = class.Game()`
- [ ] `my_game = class(Game)`
- [x] `my_game = Game()`
- [ ] `my_game = Game.create()`
[Reference](https://www.w3schools.com/python/python_classes.asp)
[Reference](https://www.geeksforgeeks.org/python-map-function/)
```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]
```
#### Q22. If you don't explicitly return a value from a function, what happens?
5 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] It is used to skip the `yield` statement of a generator and return a value of None.
- [x] It is a null operation used mainly as a placeholder in functions, classes, etc.
- [ ] It is used to pass control from one statement block to another.
- [ ] It is used to skip the rest of a `while` or `for loop` and return to the start of the loop.
The pass statement is used as a placeholder for future code. When the pass statement is executed,
nothing happens, but you avoid getting an error when empty code is not allowed.
[reference](https://realpython.com/python-pass/)
#### Q24. What is the term used to describe items that may be passed into a function?
- [x] arguments
- [ ] paradigms
- [ ] attributes
- [ ] decorators
#### Q25. Which collection type is used to associate values with unique keys?
- [ ] `slot`
- [x] `dictionary`
- [ ] `queue`
- [ ] `sorted list`
[Reference](https://www.w3schools.com/python/python_dictionaries.asp)
[Reference](https://www.w3schools.com/python/python_for_loops.asp)
#### Q27. 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?
- [x] 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.
- [ ] 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.
- [ ] The runtime cannot be determined unless you know how many nodes are in the singly linked
list.
- [ ] The runtime is O(1) because you can index directly to a node in a singly linked list.
#### Q28. Given the following three lists, 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
[('Apples', 5, 1.50),
('Oranges', 3, 2.25),
('Bananas', 4, 0.89)]
```
6 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] A
```python
output = []
return output
```
- [x] B
```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
```
- [ ] C
```python
groceries = zip(fruits, quantities, prices)
return groceries
>>> [
('Apples', 5, 1.50),
('Oranges', 3, 2.25),
('Bananas', 4, 0.89)
]
```
- [ ] D
```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
```
#### Q29. What happens when you use the built-in function all() on a list?
- [ ] The `all()` function returns a Boolean value that answers the question "Are all the items in
this list the same?
- [ ] The `all()` function returns True if all the items in the list can be converted to strings.
Otherwise, it returns False.
7 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] The `all()` function will return all the values in the list.
- [x] The `all()` function returns True if all items in the list are evaluated to True. Otherwise,
it returns False.
[Reference](https://www.geeksforgeeks.org/python-all-function/)
**Explanation:** `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 of them are true.')
else:
print('There is an imposter.')
#### Q30. 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.)_
- [x] A
```python
>>> dice = Game()
>>> dice.roll()
```
- [ ] B
```python
>>> dice = Game(self)
>>> dice.roll(self)
```
- [ ] C
```python
>>> dice = Game()
>>> dice.roll(self)
```
- [ ] D
```python
>>> dice = Game(self)
>>> dice.roll()
```
- [ ] Backtracking
- [ ] Dynamic programming
- [ ] Decrease and conquer
- [x] Divide and conquer
Both merge sort and quicksort employ a common algorithmic paradigm based on recursion. This
paradigm, divide-and-conquer, breaks a problem into subproblems that are similar to the original
problem, recursively solves the subproblems, and finally combines the solutions to the subproblems
to solve the original problem.
[reference](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/divide-
8 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
and-conquer-
algorithms#:~:text=Both%20merge%20sort%20and%20quicksort,to%20solve%20the%20original%20problem.)
#### Q32. What is the runtime complexity of the list's built-in `.append()` method?
This function has constant time complexity i.e. O(1), because lists are randomly accessed so the
last element can be reached in O(1) time that's why the time taken to add the new element at the
end of the list is O(1).
#### Q33. What is the key difference between a `set` and a `list`?
- [ ] Abstraction means that a different style of code can be used since many details are already
known to the program behind the scenes.
- [x] Abstraction means the implementation is hidden from the user, and only the relevant data or
information is shown.
- [ ] Abstraction means that the data and the functionality of a class are combined into one
entity.
- [ ] Abstraction means that a class can inherit from more than one parent class.
```python
def print_alpha_nums(abc_list, num_list):
for char in abc_list:
for num in num_list:
print(char, num)
return
- [x] A
```python
a 1
a 2
a 3
b 1
b 2
b 3
c 1
c 2
9 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
c 3
```
- [ ] B
```python
['a', 'b', 'c'], [1, 2, 3]
```
- [ ] C
```python
aaa
bbb
ccc
111
222
333
```
- [ ] D
```python
a 1 2 3
b 1 2 3
c 1 2 3
```
#### Q36. Pick the correct representation of doctest for a function in Python.
- [ ] A
```python
def sum(a, b):
# a = 1
# b = 2
# sum(a, b) = 3
return a + b
```
- [ ] B
```python
def sum(a, b):
"""
a = 1
b = 2
sum(a, b) = 3
"""
return a + b
```
- [x] C
```python
def sum(a, b):
"""
>>> a = 1
>>> b = 2
>>> sum(a, b)
10 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
3
"""
return a + b
```
- [ ] D
```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 the build-in doctest module
#### Q37. 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?
- [ ] When instantiating an object, the object doesn't inherit any of the parent class's methods.
- [ ] When instantiating an object, the object will inherit the methods of whichever parent class
has more methods.
- [ ] When instantiating an object, the programmer must specify which parent class to inherit
methods from.
- [x] An instance of the Game class will inherit whatever methods the BoardGame and LogicGame
classes have.
**Example**
```python
# namedtuple function accepts the following arguments to generate a class
from collections import namedtuple
>>> Point = namedtuple('Point',['x','y'])
>>> point = Point(100, 200)
>>> point
Point(x=100, y=200)
[Reference](https://www.geeksforgeeks.org/namedtuple-in-python/?ref=lbp)
#### Q39. What symbol(s) do you use to assess equality between two elements?
11 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] `&&`
- [ ] `=`
- [x] `==`
- [ ] `||`
#### Q40. 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
}
```
#### Q41. What value would be returned by this check for equality?
`5 != 6`
- [ ] `yes`
- [ ] `False`
- [x] `True`
- [ ] `None`
- [ ] It makes classes aware of each other if more than one class is defined in a single code
file.
- [ ] It is included to preserve backward compatibility from Python 3 to Python 2, but it no
longer needs to be used in Python 3.
- [x] It is a method that acts as a constructor and is called automatically whenever a new object
is created from a class. It sets the initial state of a new object.
- [ ] It initializes any imports you may have included at the top of your file.
[Reference](https://www.geeksforgeeks.org/__init__-in-python/)
**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'
```
- [ ] `How many microprocessors it would take to run your code in less than one second`
- [ ] `How many lines of code are in your code file`
- [x] `The amount of space taken up in memory as a function of the input size`
- [ ] `How many copies of the code file could fit in 1 GB of memory`
12 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
#### Q44. What is the correct syntax for creating a variable that is bound to a dictionary?
#### Q45. What is the proper way to write a list comprehension that represents all the keys in
this dictionary?
#### Q46. What is the purpose of the `self` keyword when defining or calling methods on an
instance of an object?
- [ ] `self` refers to the class that was inherited from to create the object using `self`.
- [ ] 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.
- [ ] `self` means that no other arguments are required to be passed into the method.
- [x] `self` refers to the instance whose method was called.
**Explanation:** - Try running the example of the Q42 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 it hasn't
been specified, which is the instance itself.
- [ ] A class method is a regular function that belongs to a class, but it must return None.
- [x] A class method can modify the state of the class, but it can't directly modify the state of
an instance that inherits from that class.
- [ ] A class method is similar to a regular function, but a class method doesn't take any
arguments.
- [ ] A class method holds all of the data for a particular class.
[Reference](https://pynative.com/python-class-method/)
Class methods are methods that are called on the class itself, not on a specific object instance.
Therefore, it belongs to a class level, and all class instances share a class method.
#### Q48. What does it mean for a function to have linear runtime?
- [ ] You did not use very many advanced computer programming concepts in your code.
- [ ] The difficulty level your code is written at is not that high.
- [ ] It will take your program less than half a second to run.
- [x] The amount of time it takes the function to complete grows linearly as the input size
increases.
The use of underscores as word separators dates back to the late 1960s. It is particularly
associated with C, is found in The C Programming Language (1978), and contrasted with the Pascal
case (a type of camel case). However, the convention traditionally had no specific name: the
13 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[reference](https://en.wikipedia.org/wiki/Snake_case)
#### Q50. According to the PEP 8 coding style guidelines, how should constant values be named in
Python?
- [ ] in camel case without using underscores to separate words -- e.g. `maxValue = 255`
- [ ] in lowercase with underscores to separate words -- e.g. `max_value = 255`
- [x] in all caps with underscores separating words -- e.g. `MAX_VALUE = 255`
- [ ] in the mixed case without using underscores to separate words -- e.g. `MaxValue = 255`
Use an uppercase single letter, word, or words. Separate words with underscores to improve
readability.
[Reference](https://realpython.com/python-pep8/)
- [ ] A deque adds items to one side and removes items from the other side.
- [ ] A deque adds items to either or both sides but only removes items from the top.
- [x] A deque adds items at either or both ends and removes items at either or both ends.
- [ ] A deque adds items only to the top but removes them from either or both sides.
Deque or Double Ended Queue is a generalized version of the Queue data structure that allows
inserting and deletion at both ends.
[reference](https://www.geeksforgeeks.org/deque-set-1-introduction-applications/?ref=gcse)
#### Q52. What is the correct syntax for creating a variable that is bound to a set?
#### Q53. 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
```
- [x] :
14 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
def __init__(self):
pass
```
#### Q54. Which of the following is TRUE About how numeric data would be organized in a Binary
Search Tree?
- [x] For any given node in a binary search tree, the value of the node is greater than all the
values in the node's left subtree and less than the ones in its right subtree.
- [ ] Binary Search Tree cannot be used to organize and search through numeric data, given the
complications that arise with very deep trees.
- [ ] 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 be ordered
in any particular way.
- [ ] The smallest numeric value would go in the topmost 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 node.
In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is
a rooted binary tree data structure with the key of each internal node being greater than all the
keys in the respective node's left subtree and less than the ones in its right subtree.
[reference](https://en.wikipedia.org/wiki/
Binary_search_tree#:~:text=In%20computer%20science%2C%20a%20binary,ones%20in%20its%20right%20subtr
ee.)
- [ ] A decorator is similar to a class and should be used if you are doing functional programming
instead of object-oriented programming.
- [ ] A decorator is a visual indicator to someone reading your code that a portion of your code
is critical and should not be changed.
- [x] You use the decorator to alter the functionality of a function without having to modify the
function code.
- [ ] An import statement is preceded by a decorator, python knows to import the most recent
version of whatever package or library is being imported.
Decorators allow us to wrap another function to extend the behavior of the wrapped function,
without permanently modifying it.
[reference](https://www.geeksforgeeks.org/decorators-in-python/)
- [ ] Only in some situations, as loops are used only for certain types of programming.
- [x] When you need to check every element in an iterable of known length.
- [ ] When you want to minimize the use of strings in your code.
- [ ] When you want to run code in one file for a function in another file.
[Reference](https://www.interviewbit.com/python-cheat-sheet/)
#### Q57. What is the most self-descriptive way to define a function that calculates sales tax on
a purchase?
- [ ] A:
```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
```
15 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] B:
```python
def tx(amt):
''' Gets the tax on an amount.'''
```
- [ ] C:
```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.'''
```
- [x] D:
```python
def calculate_sales_tax(subtotal):
pass
```
#### Q58. What would happen if you did not alter the state of the element that an algorithm is
operating on recursively?
- [ ] You do not have to alter the state of the element the algorithm is recursing on.
- [ ] You would eventually get a KeyError when the recursive portion of the code ran out of items
to recurse on.
- [x] You would get a RuntimeError: maximum recursion depth exceeded.
- [ ] The function using recursion would return None.
[explanation](https://www.python-course.eu/python3_recursive_functions.php#Definition-of-
Recursion)
#### Q59. What is the runtime complexity of searching for an item in a binary search tree?
- [ ] The runtime for searching in a binary search tree is O(1) because each node acts as a key,
similar to a dictionary.
- [ ] The runtime for searching in a binary search tree is O(n!) because every node must be
compared to every other node.
- [x] The runtime for searching in a binary search tree is generally O(h), where h is the height
of the tree.
- [ ] The runtime for searching in a binary search tree is O(n) because every node in the tree
must be visited.
[explanation](https://www.geeksforgeeks.org/binary-search-tree-data-structure/)
- [ ] 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.
- [ ] You use a `mixin` to allow a decorator to accept keyword arguments.
- [ ] You use a `mixin` to make sure that a class's attributes and methods don't interfere with
global variables and functions.
- [x] If you have many classes that all need to have the same functionality, you'd use a `mixin`
to define that functionality.
16 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[explanation](https://www.youtube.com/watch?v=zVFLBfqV-q0)
#### Q61. What is the runtime complexity of adding an item to a stack and removing an item from a
stack?
- [ ] Add items to a stack in O(1) time and remove items from a stack on O(n) time.
- [x] Add items to a stack in O(1) time and remove items from a stack in O(1) time.
- [ ] Add items to a stack in O(n) time and remove items from a stack on O(1) time.
- [ ] Add items to a stack in O(n) time and remove items from a stack in O(n) time.
#### Q62. Which statement accurately describes how items are added to and removed from a stack?
- [ ] a stack adds items to one side and removes items from the other side.
- [x] a stack adds items to the top and removes items from the top.
- [ ] a stack adds items to the top and removes items from anywhere in the stack.
- [ ] a stack adds items to either end and removes items from either end.
- [x] 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.
- [ ] The base case is a summary of the overall problem that needs to be solved.
- [ ] The base case is passed in as an argument to a function whose body makes use of recursion.
- [ ] The base case is similar to a base class, in that it can be inherited by another object.
#### Q64. Why is it considered good practice to open a file from within a Python script by using
the `with` keyword?
- [ ] The `with` keyword lets you choose which application to open the file in.
- [ ] The `with` keyword acts like a `for` loop, and lets you access each line in the file one by
one.
- [ ] There is no benefit to using the `with` keyword for opening a file in Python.
- [x] 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.
It is good practice to use the 'with' keyword when dealing with file objects. The advantage is
that the file is properly closed after its suite finishes, even if an exception is raised at some
point. Using with is also much shorter than writing equivalent try-finally blocks:
**example**
```python
>>> f = open('workfile', 'w', encoding="utf-8")
>>> with open('workfile', encoding="utf-8") as f:
read_data = f.read()
# We can check that the file has been automatically closed.
>>> f.closed
True
```
[Reference](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files)
- [x] Virtual environments create a "bubble" around your project so that any libraries or packages
you install within it don't affect your entire machine.
- [ ] Teams with remote employees use virtual environments so they can share code, do code
reviews, and collaborate remotely.
- [ ] 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.
17 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] Virtual environments are tied to your GitHub or Bitbucket account, allowing you to access
any of your repos virtually from any machine.
#### Q66. What is the correct way to run all the doctests in a given file from the command line?
There is also a command line shortcut for running testmod(). You can instruct the Python
interpreter to run the doctest module directly from the standard library and pass the module
name(s) on the command line:
`python -m doctest -v example.py`
This will import example.py as a standalone module and run testmod() on it. Note that this may not
work correctly if the file is part of a package and imports other submodules from that package.
[reference](https://docs.python.org/3/library/doctest.html)
[tutorial video](https://www.youtube.com/watch?v=P8qm0VAbbww&t=180s)
- [ ] any function that makes use of scientific or mathematical constants, often represented by
Greek letters in academic writing
- [ ] a function that gets executed when decorators are used
- [ ] any function whose definition is contained within five lines of code or fewer
- [x] a small, anonymous function that can take any number of arguments but has only expression to
evaluate
[Reference](https://www.guru99.com/python-lambda-function.html)
**Explanation:**
> The lambda notation is an anonymous function that can take any number of arguments with only a
single expression (i.e., cannot be overloaded). It has been introduced in other programming
languages, such as C++ and Java. The lambda notation allows programmers to "bypass" function
declaration.
#### Q68. What is the primary difference between lists and tuples?
- [ ] You can access a specific 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
- [x] 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.
- [ ] 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.
- [ ] Lists can hold several data types inside them at once, but tuples can only hold the same
data type if multiple elements are present.
[Reference](https://www.geeksforgeeks.org/python-difference-between-list-and-tuple/)
- [ ] None
- [x] An iterable object
- [ ] A linked list data structure from a non-empty list
- [ ] All the keys of the given dictionary
#### Q70. What is the difference between class attributes and instance attributes?
18 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [x] Class attributes are shared by all instances of the class. Instance attributes may be unique
to just that instance
- [ ] There is no difference between class attributes and instance attributes
- [ ] Class attributes belong just to the class, not to the instance of that class. Instance
attributes are shared among all instances of a class
#### Q71. What is the correct syntax for creating an instance method?
- [ ] :
```python
def get_next_card():
# method body goes here
```
- [x] :
```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
```
[Reference](https://realpython.com/python-comments-guide/)
#### Q74. What is the correct syntax for replacing the string `apple` in the list with the string
`orange`?
```python
my_list = ['kiwi', 'apple', 'banana']
```
- [ ] `orange = my_list[1]`
- [x] `my_list[1] = 'orange'`
- [ ] `my_list['orange'] = 1`
19 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] `my_list[1] == orange`
#### Q75. What will happen if you use a while loop and forget to include logic that eventually
causes the while loop to stop?
- [ ] Nothing will happen; your computer knows when to stop running the code in the while loop.
- [ ] You will get a KeyError.
- [x] Your code will get stuck in an infinite loop.
- [ ] You will get a WhileLoopError.
- [x] A queue adds items to either end and removes items from either end.
- [ ] A queue adds items to the top and removes items from the top.
- [ ] A queue adds items to the top and removes items from anywhere in, a list.
- [ ] A queue adds items to the top and removes items from anywhere in the queue.
#### Q77. Which choice is the most syntactically correct example of conditional branching?
- [x] A:
```python
num_people = 5
- [ ] B:
```python
num_people = 5
- [ ] C:
```python
num_people = 5
- [ ] D:
```python
if num_people > 10;
20 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] `defaultdict` will automatically create a dictionary for you that has keys which are the
integers 0-10.
- [ ] `defaultdict` forces a dictionary to only accept keys that are of the types specified when
you created the `defaultdict` (such as strings or integers).
- [x] 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`.
- [ ] `defaultdict` stores a copy of a dictionary in memory that you can default to if the
original gets unintentionally modified.
**example**
```python
# Function to return a default
# values for keys that are not
# present
def def_value():
return "Not Present"
[reference](https://www.geeksforgeeks.org/defaultdict-in-python/)
#### Q79. What is the correct syntax for adding a key called `variety` to the `fruit_info`
dictionary that has a value of `Red Delicious`?
**Simple Example**
```python
i = 1
while i<6:
print('Countdown:',i)
i = i + 1
```
#### Q81. What is the correct syntax for defining an `__init__()` method that sets instance-
21 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] :
```python
def __init__(self, attr1, attr2):
attr1 = attr1
attr2 = attr2
```
- [ ] :
```python
def __init__(attr1, attr2):
attr1 = attr1
attr2 = attr2
```
- [x] :
```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`.
#### Q82. 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
```
- [ ] :
22 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
3
2
1
```
- [ ] :
```python
3
3
2
2
1
1
```
- [x] :
```python
1
2
3
```
#### Q83. In Python, when using sets, you use **\_** to calculate the intersection between two
sets and **\_** to calculate the union.
- [ ] `Intersect`; `union`
- [ ] `|`; `&`
- [x] `&`; `|`
- [ ] `&&`; `||`
```python
import numpy as np
np.ones([1,2,3,4,5])
```
- [ ] It returns a 5x5 matrix; each row will have the values 1,2,3,4,5.
- [ ] It returns an array with the values 1,2,3,4,5.
- [ ] It returns five different square matrices filled with ones. The first is 1x1, the second
2x2, and so on to 5x5.
- [x] It returns a 5-dimensional array of size 1x2x3x4x5 filled with 1s.
[Reference](https://www.geeksforgeeks.org/numpy-ones-python/)
#### Q85. You encounter a FileNotFoundException while using just the filename in the `open`
function. What might be the easiest solution?
```python
{x for x in range(100) if x%3 == 0}
```
23 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
#### Q87. What does the // operator in Python 3 allow you to do?
- [x] `datetime`
- [ ] `dateday`
- [ ] `daytime`
- [ ] `timedate`
#### Q89. What is the correct syntax for defining a class called Game?
[reference here](https://docs.python.org/3/tutorial/classes.html)
#### Q90. What is the correct syntax for calling an instance method on a class named Game?
#### Q91. What is the output of this code? (NumPy has been imported as np.)?
```python
a = np.array([1,2,3,4])
print(a[[False, True, False, False]])
```
- [ ] `{0,2}`
- [x] `[2]`
- [ ] `{2}`
- [ ] `[0,2,0,0]`
#### Q92. Suppose you have a string variable defined as y="stuff;thing;junk;". What would be the
output from this code?
```python
z = y.split(';')
len(z)
```
- [ ] 17
- [x] 4
- [ ] 0
- [ ] 3
24 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
**Explanation:**:
```python
y="stuff;thing;junk"
len(z) ==> 3
y="stuff;thing;junk;"
len(z) ==> 4
```
```python
num_list = [1,2,3,4,5]
num_list.remove(2)
print(num_list)
```
- [ ] `[1,2,4,5]`
- [x] `[1,3,4,5]`
- [ ] `[3,4,5]`
- [ ] `[1,2,3]`
**Explanation:**: `.remove()` is based on the value of the item, not the index; here, it is
removing the item matching "2". If you wanted to remove an item based on its index, you would use
`.pop()`.
```python
num_list = [1,2,3,4,5]
num_list.pop(2)
>>> [1,2,4,5]
num_list.remove(2)
>>> [1,3,4,5]
```
#### Q94. Which command will create a list from 10 down to 1? Example:
`[10,9,8,7,6,5,4,3,2,1]`
- [ ] `reversed(list(range(1,11)))`
- [ ] `list(reversed(range(1,10)))`
- [ ] `list(range(10,1,-1))`
- [x] `list(reversed(range(1,11)))`
[Reference](https://www.w3schools.com/python/python_tuples.asp)
#### Q95. Which fragment of code will print the same output as this fragment?
```Python
import math
print(math.pow(2,10)) # prints 2 elevated to the 10th power
```
- [ ] :
```python
print(2^10)
```
25 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [x] :
```python
print(2**10)
```
- [ ] :
```python
y = [x*2 for x in range(1,10)]
print(y)
```
- [ ] :
```python
y = 1
for i in range(1,10):
y = y * 2
print(y)
```
[Reference](https://www.digitalocean.com/community/tutorials/how-to-do-math-in-python-3-with-
operators#:~:text=The%20**%20operator%20in%20Python,multiplied%20by%20itself%203%20times.)
#### Q96. Elements surrounded by `[]` are **\_**, `{}` are **\_**, and `()` are **\_**.
[Reference](https://www.geeksforgeeks.org/differences-and-applications-of-list-tuple-set-and-
dictionary-in-python/)
#### Q97. What is the output of this code? (NumPy has been imported as np.)
```python
table = np.array([
[1,3],
[2,4]])
print(table.max(axis=1))
```
- [ ] `[2, 4]`
- [x] `[3, 4]`
- [ ] `[4]`
- [ ] `[1,2]`
[Reference](https://colab.research.google.com/drive/1PRGf7Wgcr_gQk7snnxxuc5rL9O1ky9Xg?usp=sharing)
```python
number = 3
print (f"The number is {number}")
```
26 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[Reference](https://colab.research.google.com/drive/1PRGf7Wgcr_gQk7snnxxuc5rL9O1ky9Xg?usp=sharing)
#### Q99. Which syntax correctly creates a variable that is bound to a tuple?
[Reference](https://beginnersbook.com/2018/02/python-tuple/)
#### Q100. Which mode is not a valid way to access a file from within a Python script?
- [ ] `write('w')`
- [x] `scan('s')`
- [ ] `append('a')`
- [ ] `read('r')`
1. [Reference](https://docs.python.org/3/library/functions.html#open)
2. [Reference](https://www.w3schools.com/python/ref_list_append.asp)
#### Q101. NumPy allows you to multiply two arrays without a for loop. This is an example of \_.
- [x] Vectorization.
- [ ] Attributions.
- [ ] Acceleration.
- [ ] Functional programming.
#### Q102. What built-in Python data type can be used as a hash table?
- [ ] `set`
- [ ] `list`
- [ ] `tuple`
- [x] `dictionary`
#### Q103. Which Python function allows you to execute Linux shell commands in Python?
- [ ] `sys.exc_info()`
- [x] `os.system()`
- [ ] `os.getcwd()`
- [ ] `sys.executable`
#### Q104. 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?
```python
my_dictionary = {
'A': 1,
'B': 2,
'C': 3,
'D': 4,
'E': 5
}
```
- [x] <br>
```python
letters = []
27 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
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 numbers).
The rest of the options return a list of the keys.
#### Q105. 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?
- [ ] `set_printparams`
- [x] `set_printoptions`
- [ ] `set_fullprint`
- [ ] `setp_printwhole`
- [x] 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.
- [ ] You use `try/except` blocks inside of unit tests so that the unit tests will always pass.
- [ ] 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.
- [ ] You use `try/except` blocks so that none of your functions or methods return `None`.
[Reference](https://runestone.academy/ns/books/published/fopp/Exceptions/using-
exceptions.html#:~:text=The%20reason%20to%20use%20try,you're%20writing%20the%20code)
#### Q107. In Python, how can the compiler identify the inner block of a for loop?
#### Q108. What Python mechanism is best suited for telling a user they are using a deprecated
function
- [ ] `sys.stdout`
- [ ] Traceback
- [x] Warnings
- [ ] Exceptions
#### Q109. What will be the value of `x` after running this code?
```python
x = {1,2,3,4,5}
x.add(5)
x.add(6)
```
- [ ] `{1, 2, 3, 4, 5, 5, 6}`
- [ ] `{5, 6, 1, 2, 3, 4, 5, 6}`
- [ ] `{6, 1, 2, 3, 4, 5}`
- [x] `{1, 2, 3, 4, 5, 6}`
**Explanation:** The `.add()` method adds the element to the set only if it doesn't exist.
#### Q110. How would you access and store all of the keys in this dictionary at once?
28 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
fruit_info = {
'fruit': 'apple',
'count': 2,
'price': 3.5
}
```
- [ ] `my_keys = fruit_info.to_keys()`
- [ ] `my_keys = fruit_info.all_keys()`
- [ ] `my_keys = fruit_info.keys`
- [x] `my_keys = fruit_info.keys()`
```python
def be_friendly(greet = "How are you!", name):
pass
```
#### Q112. Given that NumPy is imported as `np`, which choice will return `True`?
- [x] :
```python
a = np.zeros([3,4])
b = a.copy()
np.array_equal(a,b)
```
- [ ] :
```python
a = np.empty([3,4])
b = np.empty([3,4])
np.array_equal(a,b)
```
- [ ] :
```python
a = np.zeros([3,4])
b = np.zeros([4,3])
np.array_equal(a,b)
```
- [ ] :
```python
a = np.array([1, np.nan])
np.array_equal(a,a)
```
29 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
#### Q114. In this code fragment, what will the values of c and d be equivalent to?
```python
import numpy as np
a = np.array([1,2,3])
b = np.array([4,5,6])
c = a*b
d = np.dot(a,b)
```
- [ ] A
```python
c = [ a[1] * b[1], a[2] * b[2], a[3] * b[3] ]
d = sum(c)
```
- [ ] B
```python
c = a[0] * b[0], a[1] * b[1], a[2] * b[2]
- [ ] C
```python
c = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]
d = sum(a) + sum(b)
```
- [x] D
```python
c = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]
d = sum(c)
```
#### Q115. What two functions within the NumPy library could you use to solve a system of linear
equations?
**Explanation:** Understanding this answer requires knowledge of linear algebra. Some systems of
equations can be solved by the method of _diagonalization_, which involves finding the
**eigenvectors and eigenvalues** of the system's matrix and multiplying related matrices.
#### Q116. What is the correct syntax for creating a variable that is bound to a list?
30 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[Reference](https://www.tutorialspoint.com/python/python_lists.htm)
#### Q117. 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]
```
- [ ] mode
- [ ] average
- [ ] mean
- [x] median
**Explanation:** `//` is the operator for floor division, which is a normal division operation
that returns the largest possible integer, either less than or equal to the normal division
result. Here it is used to find the median, which is the value separating the higher half from the
lower half of a data sample, by finding the index of the list item in the middle of the list.
(This is sufficient for a list with an odd number of items; if the list had an even number of
items, you would average the values of the two middle items to find the median value.)
#### Q118. What are the two main data structures in the Pandas library?
[Reference](https://pandas.pydata.org/docs/user_guide/dsintro.html)
#### Q119. 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?
[Reference](https://www.w3schools.com/python/numpy/numpy_array_reshape.asp)
- [ ] Dictionary
- [ ] List
- [ ] Set
- [x] String
[Reference](https://www.tutorialspoint.com/python_text_processing/python_string_immutability.htm)
```python
def myFunction(country = "France"):
print("Hello, I am from", country)
myFunction("Spain")
myFunction("")
myFunction()
```
31 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] :
```python
Hello, I am from Spain
Hello, I am from
Hello, I am from
```
- [ ] :
```python
Hello, I am from France
Hello, I am from France
Hello, I am from France
```
- [x] :
```python
Hello, I am from Spain
Hello, I am from
Hello, I am from France
```
- [ ] :
```python
Hello, I am from Spain
Hello, I am from France
Hello, I am from France
```
#### Q122. Choose the option below for which instance of the class cannot be created.
- [ ] Anonymous Class
- [ ] Parent Class
- [ ] Nested Class
- [x] Abstract Class
[Reference](https://www.scaler.com/topics/python/data-abstraction-in-python/)
#### Q123. Using Pandas, we load a data set from Kaggle, as structured in the image below. Which
command will return the total number of survivors?

- [x] `sum(titanic['Survived'])`
- [ ] `[x for x in titanic['Survived'] if x == 1]`
- [ ] `len(titanic["Survived"])`
- [ ] `sum(titanic['Survived']==0)`
#### Q124. How would you create a list of tuples matching these lists of characters and actors?
```python
characters = ["Iron Man", "Spider Man", "Captain America"]
actors = ["Downey", "Holland", "Evans"]
32 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
d = {}
```python
{x : x*x for x in range(1,100)}
```
- [ ] A dictionary with `x` as a key, and `x` squared as its value; from 1 to 100.
- [x] A dictionary with `x` as a key, and `x` squared as its value; from 1 to 99.
- [ ] A set of tuples, consisting of (`x`, `x` squared); from 1 to 99.
- [ ] A list with all numbers squared from 1 to 99.
#### Q126. Jaccard Similarity is a formula that tells you how similar two sets are. It is defined
as the cardinality of the intersection divided by the cardinality of the union. Which choice is an
accurate implementation in Python?

[Reference](https://docs.python.org/3/tutorial/datastructures.html?highlight=set#sets.)
- [ ] Long
- [ ] Int
- [ ] Float
- [x] Double
```python
[1,2,3] * 3
```
- [ ] `[3,2,3]`
- [x] `[1, 2, 3, 1, 2, 3, 1, 2, 3]`
- [ ] You will get a type error.
- [ ] `[3,6,9]`
#### Q129. Given a list defined as numbers = `[1,2,3,4]`, what is the value of `numbers[-2]`?
33 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] 1
- [x] 3
- [ ] 2
- [ ] An IndexError exception is thrown.
- [x] Strings can be enclosed by double quotes (") or single quotes (').
- [ ] Strings can only be enclosed in single quotes (').
- [ ] Single character strings must be enclosed in single quotes ('), and the rest must be
enclosed in double quotes (").
- [ ] Strings can only be enclosed in double quotes (").
#### Q131. What is the correct syntax for defining an `_init_()` method that takes no parameters?
- [ ] `def*init*(self): pass`
- [ ] `class*init*(self): pass`
- [ ] `class*init*(): pass`
- [x] `def*init*(): pass`
#### Q132. Suppose you need to use the `sin` function from the `math` library. What is the correct
syntax for importing only that function?
- [ ] `using math.sin`
- [ ] `import math.sin`
- [x] `from math import sin`
- [ ] `import sin from math`
[Reference](https://www.datacamp.com/tutorial/modules-in-python#more-on-import-statements)
#### Q133. What do you get if you apply numpy.sum() to a list that contains only Boolean values?
- [ ] `0`
- [x] `the count of all True values`
- [ ] `a type error`
- [ ] `None`
```python
print ("foo" if (256).bit_length() > 8 else "bar")
```
- [ ] `True`
- [x] `foo`
- [ ] You will get an error message because constant integer values are not classes.
- [ ] `bar`
#### Q135. If you do not explicitly return a value from a function, what happens?
34 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [x] If the return keyword is absent the function will return `None`.
#### Q136. It is often the case that the pandas library is used for **_ data and NumPy for _**
data.
- [ ] string; numerical
- [ ] unstructured; structured
- [ ] numerical; tabular
- [x] tabular; numerical
* Explanation: The Pandas library is commonly used for working with tabular data, such as data in
the form of tables or spreadsheets. It provides data structures and functions for data
manipulation and analysis. On the other hand, NumPy is a powerful library for numerical computing
in Python, and it is often used for performing mathematical operations on numerical data, such as
arrays and matrices.
#### Q137. What do you need to do to install additional packages into Python?
#### Q138. The image below was created using Matplotlib. It is a distribution plot of a list of
integers filled with numbers using the function **\_** and plotted with **\_**.

- [ ] `random.uniform(0,50);plt.hist`
- [x] `random.gauss(50,20);plt.hist`
- [ ] `random();plt.scatter`
- [ ] `random.triangular(0,50);plt.bar`
[Reference](https://www.geeksforgeeks.org/random-gauss-function-in-python/)
#### Q139. In this code fragment, what will be the values of `a` and `b`?
```python
import numpy as np
a = np.arange(100)
b = a[50:60:2]
```
- [x] `a`: all integers from 0 to 99 (inclusive); `b`: all even integers from 50 to 58
(inclusive).
- [ ] `a`: all integers from 0 to 100 (inclusive); `b`: all even integers from 50 to 60
(inclusive).
- [ ] `a`: all integers from 0 to 99 (inclusive); `b`: all even integers from 50 to 60
(inclusive).
- [ ] `a`: all integers from 0 to 99 (inclusive); `b`: all odd integers from 49 to 59 (inclusive).
#### Q140. When using NumPy in Python, how do you check the dimensionality (number and length of
dimensions) of an object called `my_object`?
- [ ] `my_object.get_shape()`
- [x] `my_object.shape`
- [ ] `my_object.dim()`
- [ ] `len(my_object)`
#### Q141. Assume you have a non-empty list named `mylist` and you want to search for a specific
value. The minimum number of comparisons will be \_**_ and the maximum number of comparisons will
35 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
be _**?
- [ ] `len(mylist); len(mylist)`
- [x] `1; len(mylist)`
- [ ] `2; len(mylist)`
- [ ] `0; len(mylist)`
**Explanation:** Can use a break statement and the value being searched can be the first element
of the list, given that it is non-empty.
#### Q142. If a function does not have a return statement, what does it return?
- [ ] `0`
- [ ] `True`
- [x] `None`
- [ ] `False`
#### Q143. Suppose you want to double-check if two matrices can be multiplied using NumPy for
debugging purposes. How would you complete this code fragment by filling in the blanks with the
appropriate variables?
```python
import numpy as np
if _____ == ______ :
print('The matrices can be multiplied!')
return True
else:
return False
```
- [ ] columnsMat1; rowsMat1;
- [x] columnsMat1; rowsMat2;
- [ ] columnsMat1; columnsMat2;
- [ ] columnsMat2; rowsMat1;
[reference](https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:matrices/
x9e81a4f98389efdf:multiplying-matrices-by-matrices/a/multiplying-matrices#).
A matrix can be multiplied by any other matrix that has the same number of rows as the first
columns. I.E. A matrix with 2 columns can be multiplied by any matrix with 2 rows
- [ ] [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
- [ ] [1,2,3,4,5]
- [ ] [(1, 2), (2, 3), (3, 4)]
- [x] [(1, 2), (2, 3), (3, 4), (4, 5)]
#### Q145. In Python, a class method must have \_**\_ as a function decorator, and the first
parameter of the method will be a reference to \_\_**.
36 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[Reference](https://docs.python.org/3/library/functions.html#classmethod)
#### Q146. Which snippet of code will print _My name is Joffrey, son of Robert_?
- [ ] :
```python
class Father():
name = 'Robert'
class Person(Father):
def __init__(self, name):
self.fathername = super.name
self.name = name
def introduce(self):
print("My name is", self.name, "son of", self.fathername)
king = Person("Joffrey")
king.introduce()
```
- [x] :
```python
class Father():
name = 'Robert'
class Person(Father):
def __init__(self, name):
self.fathername = self.name
self.name = name
def introduce(self):
print("My name is", self.name, "son of", self.fathername)
king = Person("Joffrey")
king.introduce()
```
- [ ] :
```python
class Father():
name = 'Robert'
class Person(Father):
def __init__(self, name):
self.name = name
def introduce(self):
print("My name is", self.name, "son of", super.name)
king = Person("Joffrey")
king.introduce()
```
37 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] :
```python
class Father():
name = 'Robert'
class Person(Father):
def __init__(self, name):
self.name = name
def introduce(self):
print("My name is", self.name, "son of", base.name)
king = Person("Joffrey")
king.introduce()
```
**Explanation:** In the first, super does not have `.name` (should be `self.name`). The third
drops Robert, and `base` is not defined in the 4th.
#### Q147. What does this code output in the console, assuming defaultdict has already been
imported?
```python
animals = {
'a': ['ant', 'antelope', 'armadillo'],
'b': ['beetle', 'bear', 'bat'],
'c': ['cat', 'cougar', 'camel']
}
print(animals['b'])
print(animals['d'])
```
- [x] A
```python
['beetle', 'bear', 'bat']
[]
```
- [ ] B
```python
['beetle', 'bear', 'bat']
# an exception will be thrown
```
- [ ] C
```python
['beetle', 'bear', 'bat']
None
```
- [ ] D
```python
['bat', 'bear', 'beetle']
38 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
[]
```
**Explanation:** Dictionaries usually result in an exception when using the square bracket syntax.
Defaultdict here returns a default value dedicated by the first parameter so instead of throwing
an exception, they return the default. Note that this needs to be imported as follows: `from
collections import defaultdict`
[Reference](https://www.geeksforgeeks.org/defaultdict-in-python/)
#### Q148. What will this line of code return? (Assume `n` is already defined as any positive
integer value.)
```python
[x*2 for x in range(1,n)]
```
- [x] A list with all the even numbers less than 2\*n.
- [ ] A dictionary with all the even numbers less than 2\*n.
- [ ] A list with all the odd numbers less than 2\*n.
- [ ] A list with all the even numbers less than or equal to 2\*n.
[Reference](https://www.w3schools.com/python/ref_func_range.asp)
```python
x = 18
if x > 10:
if x > 15:
print('A')
else:
print('B')
else:
print('C')
```
- [ ] C
- [ ] A B
- [ ] B
- [x] A
- [ ] 32
- [ ] 16
- [ ] 128
- [x] No fixed length is specified.
#### Q151. What will the value of the `i` variable be when the following loop finishes its
execution?
```python
for i in range(5): pass
```
- [ ] 5
39 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
#### Q153. How many CPUs (or cores) will the Python threading library take advantage of
simultaneously?
- [x] One.
- [ ] All of the available CPUs.
- [ ] Two.
- [ ] Three.
**Explanation:**: Python threading is restricted to a single CPU at one time. The multiprocessing
library will allow you to run code on different processors.
```python
x = 5
y = 1 + (20 if x < 5 else 30)
```
- [ ] `False`
- [ ] `21`
- [ ] `2`
- [x] `31`
[Reference](https://www.w3schools.com/python/python_conditions.asp)
**Explanation:** If you have only one statement to execute, one for `if` and one for `else`, you
can put it all on the same line.
```python
x = 5
# This is the same statement expanded to multiple lines
y = 1
if (x < 5):
y += 20
else:
y += 30
```
[reference](https://docs.python.org/3/library/
pickle.html#:~:text=“Pickling”%20is%20the%20process%20whereby,back%20into%20an%20object%20hierarch
y.)
“Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and
“unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like
object) is converted back into an object hierarchy.
40 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
print("codescracker".endswith("er"))
```
- [x] `True`
- [ ] `1`
- [ ] `2`
- [ ] `False`
- [x] True
- [ ] False
```python
print("programming".center())
```
- [ ] `cr`
- [ ] `programming`
- [x] Error says `TypeError: center expected at least 1 argument, got 0`.
- [ ] None of the above.
- [ ] Tim Berners-Lee
- [ ] Ada Lovelace
- [x] Guido van Rossum
- [ ] Alan Turing
#### Q160. Which collection is ordered, changeable, and allows duplicate members?
- [ ] Set
- [ ] Tuple
- [ ] Dictionary
- [x] List
#### Q161. What will be printed in the console if you run this code?
```python
x = 1j
print(x**2 == -1)
```
- [ ] A runtime error telling you that the variable `j` has not been initialized.
- [x] `True`
- [ ] `1j`
- [ ] `False`
**Explanation:** The letter `j` acts as the imaginary unit in Python, therefore `x**2` means
`j**2` which is equal to `-1`. The statement `x**2 == -1` is evaluated as `True`.
#### Q162. What will be printed in the console if you run this code?
41 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```python
print(0xA + 0xB + 0xC)
```
- [x] `33`
- [ ] `63`
- [ ] `0xA + 0xB + 0xC`
- [ ] `None`
**Explanation:** `A`, `B` and `C` are hexadecimal integers with values `10`, `11` and `12`
respectively, so the sum of `A`, `B` and `C` is `33`.
```python
for i in range(5):
print(i)
else:
print("Done!")
```
- [ ] `1 2 3 4 5 Done!`
- [ ] `0 1 2 3 4 5 Done!`
- [x] `0 1 2 3 4 Done!`
- [ ] You will get a syntax error.
- [ ] Use lists instead of tuples when you have a collection of related but dissimilar objects.
- [ ] Use tuples instead of lists when you have a common collection of similar objects.
- [x] Use tuples instead of lists for functions that need to return multiple values.
- [ ] Use lists instead of tuples when the position of elements is important.
[Reference](https://www.scaler.com/topics/python/tuples-in-python/)
#### Q165. Consider the following code snippet that uses decorators to calculate the execution
time of the `execution_fn` function:
```python
import functools
import time
def timer(MISSING_ARG_1):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.perf_counter()
rval = func(*args, **kwargs)
end_time = time.perf_counter()
duration = end_time - start_time
print(f"Executed in {duration:.4f} seconds")
return MISSING_ARG_2
return MISSING_ARG_3
@timer
def execution_fn():
for i in range(3):
time.sleep(1)
execution_fn()
```
42 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] :
```
MISSING_ARG_1 = wrapper
MISSING_ARG_2 = rval
MISSING_ARG_3 = func
```
- [x] :
```
MISSING_ARG_1 = func
MISSING_ARG_2 = rval
MISSING_ARG_3 = wrapper
```
- [ ] :
```
MISSING_ARG_1 is empty
MISSING_ARG_2 = rval
MISSING_ARG_3 = wrapper
```
- [ ] :
```
MISSING_ARG_1 is empty
MISSING_ARG_2 = rval
MISSING_ARG_3 = func
```
#### Q166. Which of the following statements defines a new object type named `Dog` in Python?
#### Q167. To use pipelines in `scikit-learn`, import from the `scikit-learn._` submodule.
- [ ] `preprocessing`
- [x] `pipeline`
- [ ] `filters`
- [ ] `pipe_filter`
#### Q168. You should pass in a value of **\_** for the axis argument to the Pandas apply method
to apply the function to each row.
43 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] row
- [ ] col
- [x] 1
- [ ] 0
- [ ] ... pointers.
- [ ] ... points.
- [x] ... markers.
- [ ] ... none of these.
```python
a = np.array([[1, 2], [3, 4], [5, 6]])
c = a[(a > 3) & (a < 11)]
print(c)
```
#### Q171. Assume `m`, `n`, and `p` are positive integers. In the following comprehension, how
many times will the function `randint` be called?
```python
[ [ [ randint(1,100) for i in range(m) ] for j in range(n) ] for k in range(p) ]
```
- [x] `m * n * p`
- [ ] The greater value of `(m,n,p)`.
- [ ] 1 million.
- [ ] `m + n + p`
#### Q172. Suppose you have a class named `MyClass` which has multiple inheritance and methods
with the same name in its ancestors. Which class method could you call to see which method will
get priority when invoked?
- [x] `MyClass.__mro__`
- [ ] `MyClass.hierarchy()`
- [ ] `callable(MyClass)`
- [ ] `dir(MyClass)`
**Explanation:** MRO stands for Method Resolution Order. It returns a list of types the class is
derived from, in the order they are searched for methods.
#### Q173. Suppose you have a list of employees described by the code below. You want to assign
Alice the same salary as Charlie. Which choice will accomplish that?
```python
employees = {
'alice':{
'position':'Lead Developer',
'salary':1000
},
'bob':{
'position': 'Lead Artist',
'salary':2000
},
44 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
'charlie':{
'position':'cfo',
'salary':3000
}
}
```
**Explanation:** This is accessing a key in a dictionary nested inside another dictionary. The
command `employees['alice']['salary'] = employees['charlie']['salary']` assigns the value of the
`salary` key in the dictionary of the employee `charlie` to the value of the `salary` key in the
dictionary of the employee `alice`.
#### Q174. You are given this piece of code. Assume `m` and `n` are already defined as some
positive integer value. When it completes, how many tuples will my list contain?
```python
mylist = []
for i in range(m):
for j in range(n):
mylist.append((i,j))
```
- [ ] `m`
- [ ] `m + n`
- [ ] `n`
- [x] `m \* n`
**Explanation:** This code will run for `m` x `n` times, if you run this code, it will create `m`
x `n` tuples.
The first loop runs for `m` times and the inner loop will run for `n` times. The single iteration
of the first loop will only be completed when all of the `n` iterations of an inner loop are
completed. This is the same process for 2nd, and 3rd, ... `m`th iterations for outer loop.
Overall, both loops will run `m` x `n` times.
```python
{x : [y for y in range (1, x) if x % y == 0] for x in range (2, 100)}
```
- [x] A dictionary whose keys are the numbers from 2 to 99 (inclusive), and their respective
values are their factors.
- [ ] A dictionary whose keys are the numbers from 2 to 99 (inclusive), and their respective
values are a list from 1 to the key value itself (inclusive).
- [ ] A dictionary whose keys are the numbers from 2 to 99 (inclusive), and their respective
values are the even numbers from 1 to the key value itself (inclusive).
- [ ] A dictionary whose keys are the numbers from 2 to 99 (inclusive), and their respective
values are the odd numbers from 1 to the key value itself (inclusive).
- [ ] to take a snapshot of all the packages and libraries in your virtual environment
- [ ] to connect various systems, such as connecting a web front end, an API service, a database,
and a mobile app
- [x] to capture command-line arguments given at a file's runtime
45 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] to scan the health of your Python ecosystem while inside a virtual environment
- [ ] 17
- [ ] 15
- [x] 2
- [ ] 16
#### Q178. How would you create a list of tuples matching these lists of characters and actors?
```python
characters = ["Iron Man", "Spider Man", "Captain America"]
actors = ["Downey", "Holland", "Evans"]
#example output : [("Iron Man", "Downey), ("Spider Man", "Holland"), ("Captain America", "Evans")]
```
```
d = {}
for x in range(1, len(characters)):
d[x] = actors [x]
```
```
for i in range(5):
print (i)
else:
print("Done!")
```
- [x] :
```
1
2
3
4
Done!
```
```
0
1
3
4
5
Done!
```
- [ ] :
46 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
```
1
3
4
5
Done!
```
#### Q180. When is the `if __name__ == "__main__":` block executed in a Python script?
The `if __name__ == "__main__":` block is executed when the script is run directly but not when
it's imported as a module in another script.
[reference](https://docs.python.org/3/tutorial/modules.html#executing-modules-as-scripts)
#### Q181. What will be the output of the following Python code?
```python
def square(x):
return x * x
numbers = [1, 2, 3, 4, 5]
squared_numbers = map(square, numbers)
result = list(squared_numbers)
print(result)
```
The code defines a `square` function to calculate the square of a number. It then uses the `map`
function to apply this function to each element in the `numbers` list, resulting in a new
iterable. Finally, the `list` constructor is used to convert this iterable into a list. The output
will be a list of squared numbers.
[reference](https://docs.python.org/3/library/functions.html#map)
#### Q182. Which of the following is not a valid built-in function in Python?
- [ ] int
- [ ] string
- [ ] boolean
- [x] array
[Source](https://docs.python.org/3/library/functions.html)
#### Q183. Which of the following is not a valid Python data type?
- [ ] int
- [x] char
- [ ] float
- [ ] str
#### Q184. In Python, which function is used to read a line from the console input?
- [x] input()
- [ ] read_line()
47 of 48 6/14/2024, 17:14
Firefox https://raw.githubusercontent.com/Ebazhanov/linkedin-skill-assessment...
- [ ] console_input()
- [ ] getline()
[Reference](https://www.geeksforgeeks.org/taking-input-from-console-in-python/)
#### Q185.1. What will be the output of the following Python code?
48 of 48 6/14/2024, 17:14