From f4dc4d6e9445234380c309a35ab367eada0dd901 Mon Sep 17 00:00:00 2001 From: jdelucca <76178990+jdelucca@users.noreply.github.com> Date: Thu, 13 Oct 2022 00:37:17 -0500 Subject: [PATCH] 4345 (#4732) * Fixes conflict in PR #4589 * Edit formatting, esp of Q147 from #4345 and added explanation --- python/python-quiz.md | 139 ++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 61 deletions(-) diff --git a/python/python-quiz.md b/python/python-quiz.md index 66c7efc370..9c9a90da03 100644 --- a/python/python-quiz.md +++ b/python/python-quiz.md @@ -1244,7 +1244,7 @@ len(z) **Explanation**: -``` +```python y=”stuff;thing;junk” len(z) ==> 3 @@ -1655,7 +1655,7 @@ myFunction() - [ ] : -``` +```python Hello, I am from Spain Hello, I am from Hello, I am from @@ -1663,7 +1663,7 @@ Hello, I am from - [ ] : -``` +```python Hello, I am from France Hello, I am from France Hello, I am from France @@ -1671,7 +1671,7 @@ Hello, I am from France - [x] : -``` +```python Hello, I am from Spain Hello, I am from Hello, I am from France @@ -1679,7 +1679,7 @@ Hello, I am from France - [ ] : -``` +```python Hello, I am from Spain Hello, I am from France Hello, I am from France @@ -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 @@ -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'], @@ -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'] [] ``` @@ -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)] ``` @@ -2069,7 +2078,7 @@ print(animals['d']) #### Q150. What does this code print in the console? -``` +```python x = 18 if x > 10: @@ -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? @@ -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. +