PE2: Python Essentials 2 – Part 2 Summary Test Answers Full 100% 2023 2024
This is Cisco NetAcad SkillsForAll PE2: Python Essentials 2 – Part 2 Summary Test and PE2 Course Final Exam Answers full 100% in 2023 and 2024. All answers have been verified by experts.
-
The following code:
x = "\\\\" print(len(x))
- will print
1
- will print
2
- will cause an error
- will print
3
- will print
-
What information can be read using the
uname
function provided by theos
module? (Select two answers)import os os.mkdir('pictures') os.chdir('pictures') print(os.getcwd())
- Last login date.
- Current path
- Operating system name
- Hardware identifier
-
The following statement:
assert var != 0
- ia erroneous
- has no effect
- will stop the program when
var == 0
- will stop the program whrn
var !=0
-
What is he except output of the following code?
class A: A = 1 def __init__(self): self.a = 0 print(hasattr(A, 'a'))
0
True
1
False
-
What is the excepted result of the following code?
from datetime import timedelta delta = timedelta(weeks = 1, days = 7, hours = 11) print(delta * 2)
28 days, 22:00:00
2 weeks, 14 days, 22 hours
7 days, 22:00:00
- The code will raise an exception
-
What is the excepted output of the following code?
class A: def __init__(self, v=2) def set(self, v=1): self.v +=v return self.v a = A() b = a b.set() print(a.v)
1
0
2
3
-
What is the expected effect of running the following code?
class A: def __init__(self, v): self.__a = v + 1 a = A(0) print(a.__a)
- The code will raise an
AttributeError
except - The code will print
2
- The code will print
0
- The code will print
1
- The code will raise an
-
Knowing that a function named
fun()
resides in a module namedmod
, and was imported using the following statement:from mod import fun
choose the right to invoke the fun() function:
- mod:fun()
- mod::fun()
fun()
- mod.fun()
-
What output will appear after running the following snippet?
- The number of all the entities residing in the
math
module - A string containing the fully qualified name of the module
- An error message
- A list of all the entities residing in the
math
module
- The number of all the entities residing in the
-
Look at the code below:
import random # # Insert lines of code here. # print(a, b,
Which lines of code would you insert so that it is possible for the program to output the following result:
6 82 0
-
a = random.randint(0, 100) b = random.randrange(10, 100, 3) c = random.choice((0, 100, 3))
-
a = random.choice((0, 100, 3)) b = random.randrange(10, 100, 3) c = random.randint(0, 100)
-
a = random.randrange(10, 100, 3) b = random.randint(0, 100) c = random.choice((0, 100, 3))
-
a = random.randint(0, 100) b = random.choice((0, 100, 3)) c = random.randrange(10, 100, 3)
-
-
What is the expected result of the following code?
from datetime import datetime datetime_1 = datetime(2019, 11, 27, 11, 27, 22) datetime_2 = datetime(2019, 11, 27, 0, 0, 0) print(datetime_1 - datetime_2)
o days
0 days, 11:27:22
11:27:22
11 hours, 27 minutes, 22 seconds
-
What is the expected result of the following code?
import calendar calendar.setfirstweekday(calendar.SUNDAY) print(calendar.weekheader(3))
Su Mo Tu We Th We Fr Sa
Sun Mon Tue Wed Thu Fri Sat
Tu
Tue
-
what is the expected result of executing the following code?
class A:
- The code will print
c
- The code will raise an excepion
- The code will print
b
- The code will print
a
- The code will print
-
Look at the following code:
numbers [0, 2, 7, 9, 10] # Insert line of code here. print(list(foo))
Which line would you insert in order for the program to produce the expected output?
[0, 4, 49, 81, 100]
- foo = lambda num: num ** 2, numbers
- foo = lambda num: num * 2, numbers)
- foo = filter(lambda num: num ** 2, numbers)
foo = map(lambda num : num ** 2, numbers)
-
What is the expected result of executing the following code?
class I: def __init__(self): self.s = 'abc' self.i = 0 def __init__(self): return self def __next__(self): if self.i == len(self.s): raise StopIteration v = self.s[self.i] self.i +=1 return v for x in I(): print(x, end='')
- The code will print
210
- The code will print
abc
- The code will print
012
- The code will print
cba
- The code will print
-
The complied Python bytecode is stored in files which have their names ending with:
py
pyb
pc
pyc
-
Which
pip
command would you use to uninstall a previously install package?- pip delete packagename
- pip –uninstall packagename
- pip –remove packagename
- pip uninstall packagename
-
What is the excepted result of executed the following code?
try: raise Exception(1, 2, 3) except Exception as e: print(len(e.args))
- The code will raise an unhandled exception
- The code will print
2
- The code will print
3
- The code will print
1
-
What is the excepted result of executed the following snippet?
try: raise Exception except BaseException: print("a") except Exception: print("b") except: print("c")
- b
a
- An error message
- 1
-
What is the expected result of executing the following code?
class A: pass class B(A): pass class C(B): pass print(issubclass(A, C))
- The code will print
Ture
- The code will print
1
- The code will print
False
- The code will raise an exception
- The code will print
-
If you want to fill a byte array with data read in from a stream, which method you can use?
- The
read()
method - The
readbytes()
method - The
readfrom()
method - The
readinto()
method
- The
-
The following code:
print(float("1.3"))
- will print
1.3
- will print
13
- will print
1,3
- will raise a
ValueError
exception
- will print
-
The following code:
print(chr(ord('p) + 2))
will print:
q
s
r
t
-
If there are more than one
except:
branch after thetry:
clause, we can say that:- exactly one
except:
block will be executed - one or more
except:
blocks will be executed - not more than one
except:
block will be executed - none of the
except:
blocks will be executed
- exactly one
-
If the class constructor is declared in the following way:
class Class: def __init__(self, vla = 0): pass
which one of the assignments is invalid?
- object = Class(1)
- object = Class(None)
- object = Class(1, 2)
- object = Class()
-
What is the expected result of the following snippet?
try: raise Exception except: print("c") except BaseException: print("a") except Exception: print("b")
- The code will cause a syntax error
1
b
a
-
What is the expected result of the following code?
def my_fun(n): s = '+' for i in range(n): s += s yield s for x in my_fun(2): print(x, end='')
- The code will print
+
- The code will print
+++
- The code will print
++
- The code will print
++++++
- The code will print
-
Look at the following code:
numbers = [i*i for i in range(5)] # Insert line of code here. print(foo)
Which line would you insert in order for the program to produce the expected output?
[1, 9]
foo = list(filter(lambda x: x % 2, numbers))
- foo = list(filter(lambda x: x / 2, numbers))
- foo = list(map(lambda x: x % 2, numbers))
- foo = list(map(lambda x: x // 2, numbers))
-
What is the expected result of executing the following code?
def o(p): def q(): return '*' * p return q r = o(1) s = o(2) print(r() + s())
- The code will print
***
- The code will print
****
- The code will print
*
- The code will print
**
- The code will print
-
The following statement:
from a.b import c
causes the import of:
- entity
a
from moduleb
from packagec
- entity
b
from modulea
from packagec
- entity
c
from modulea
from packageb
- entity
c
from moduleb
from packagea
- entity
-
The
sys.stderr
stream is normally associaated with:- the keyboard
- the printer
- a null device
- the screen
-
What will be the output of the following code, located in the
p.py
file?print(__name__)
main
p.py
__main__
__p.py__
-
Assuming that the
open()
invocation has gone successfully, the following snippet:for x in open('file', 'rt')) print(x)
will:
- read the file character by character
- read the file line by line
- read the whole file at once
- cause an exception
-
If
a
is a stream opened in read mod, the following line:q = s.read(1)
will read:
- one line from the stream
- one kilobyte from the stream
- one buffer from the stream
- one character from the stream
-
The following line of code:
for line in open('text.txt', 'rt'):
- in invalid because
open
returns nothing - is invalid because
open
returns a non-iterable object - is invalid because
open
returns an iterable object - may be valid if
line
is a list
- in invalid because
-
What is the expected result of the following code?
import os os.mkdir('pictures') os.chdir('pictures') print(os.getcwd())
- The code will print the owner of the created directory
- The code will print the content of the created directory
- The code will print the name of the created directory
- The code will print the path to the created directory
-
Assuming that the following three files
a.py
,andc.py
reside in the same directory, what will be the output produce after running thec.py
file?# file a.py print("a", end='') # file b.py import a print("b", end='') # file c.py print("c", end='') import a import b
cab
cab
abc
bac
-
What is the expected result of executing the followinf code?
class A: def __init__(self): pass a = A(1) print(hasattr(a, 'A'))
- The code will print
1
- The code will raise an exception
- The code will print
False
- The code will print
True
- The code will print
-
The following code:
x = " \\" print(len(x))
- will print
1
- will print
3
- will print
2
- will cause an error
- will print
-
Which of the following commands would you use to check
pip
‘s version? (Select two answers)- pip version
pip --version
- pip–version
pip3 --version