Skip to content

Commit

Permalink
4345 (#4732)
Browse files Browse the repository at this point in the history
* Fixes conflict in PR #4589

* Edit formatting, esp of Q147 from #4345 and added explanation
  • Loading branch information
jdelucca authored Oct 13, 2022
1 parent c988371 commit f4dc4d6
Showing 1 changed file with 78 additions and 61 deletions.
139 changes: 78 additions & 61 deletions python/python-quiz.md
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ len(z)

**Explanation**:

```
```python
y=”stuff;thing;junk”
len(z) ==> 3

Expand Down Expand Up @@ -1655,31 +1655,31 @@ myFunction()

- [ ] :

```
```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
Expand Down Expand Up @@ -1899,7 +1899,8 @@ b = a[50:60:2]

#### Q144. Suppose you want to double-check if two matrices can be multipled using NumPy for debugging purposes. How would you complete this code fragment by filling in the blanks with the appropiate variables?

```import numpy as np
```python
import numpy as np

def can_matrices_be_multiplied (matrix1, matrix2):
rowsMat1, columnsMat1 = matrix1.shape
Expand Down Expand Up @@ -1939,77 +1940,85 @@ def can_matrices_be_multiplied (matrix1, matrix2):

- [ ] :

```
class Father():
name = 'Robert'
class Person(Father):
def __init__(self, name):
self.fathername = super.name
self.name = name
```python
class Father():
name = 'Robert'

def introduce(self):
print("My name is", self.name, "son of", self.fathername)
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()
king = Person("Joffrey")
king.introduce()

```

- [x] :

```
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)
```python
class Father():
name = 'Robert'

king = Person("Joffrey")
king.introduce()

```
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)

```
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()
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()
```
class Father():
name = 'Robert'

class Person(Father):
def __init__(self, name):
self.name = name
- [ ] :

```python
class Father():
name = 'Robert'

def introduce(self):
print("My name is", self.name, "son of", base.name)
class Person(Father):
def __init__(self, name):
self.name = name

king = Person("Joffrey")
king.introduce()
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.

#### Q148.

```
```python
animals = {
'a': ['ant', 'antelope', 'armadillo'],
'b': ['beetle', 'bear', 'bat'],
Expand All @@ -2024,28 +2033,28 @@ 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']
[]
```
Expand All @@ -2056,7 +2065,7 @@ print(animals['d'])

#### Q149. 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)]
```

Expand All @@ -2069,7 +2078,7 @@ print(animals['d'])

#### Q150. What does this code print in the console?

```
```python
x = 18

if x > 10:
Expand Down Expand Up @@ -2125,11 +2134,8 @@ for i in range(5): pass
- [ ] Two
- [ ] Three

**Explanation**:
**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 threading is restricted to a single CPU at one time. The multiprocessing library will allow you to run code on different processors.
```

#### Q156 What will be the value of y in this code?

Expand All @@ -2146,3 +2152,14 @@ y = 1 + (20 if x < 5 else 30)
**Explanation:**
If x < 5 ==> y = 1 + 20
Else y = 1 + 30


#### Q157.The process of pickling in Python includes?

- [x] conversion of a Python object hierarchy into byte stream
- [ ] conversion of a datatable into a list
- [ ] conversion of a byte stream into Python object hierarchy
- [ ] conversion of a list into a datatable

Explanation:Pickling is the process of sterilizing a Python object, that is, conversion of a byte stream into Python object hierarchy. The reverse of this process is known as unpickling.

0 comments on commit f4dc4d6

Please sign in to comment.