PCAP - Python Programming Essentials
QuizzesMódulo 5 Respuestas de prueba
1.A data structure described as LIFO is actually
one
list
pile
tree
to stack
2. If the class constructor is declared as follows
way, which of the assignments is valid?
class class
def __init__(self):
pass
object = class (object)
object = class (oneself)
object = class
object = class()
3. If there is a superclass called A and a subclass called B,
Which of the presented invocations should I place in
place of a comment?
class A:
def __init__(self):
self.a = 1
class B:
def __init__(self):
put the selected line here
self.a = 2
in that
A .__ init __ ()
A .__ init __ (auto)
A .__ init __ (1)
4. What will be the effect of executing the following code?
class A:
def __init__(self, v):
auto .__ a = v + 1
a = A (0)
print (a .__ a)
0 will be printed
it will print 2
1 will be printed
it will raise an AttributeError exception
5.¿Cuál será la salida del siguiente código?
class A:
def __init __ (self, v = 1):
self.v = v
set of definitions (self, v):
self.v = v
to return
a = A ()
print([Link](av + 1))
3
0
1
2
6. What will be the output of the following code?
class A:
X=0
def __init __ (self, v = 0):
self.Y = v
AX + = v
a = A ()
b = A (1)
c = A (2)
print (cX)
0
2
3
1
7. What will be the output of the following code?
Class A:
A=1
print(hasattr(A, 'A'))
0
False
1
True
8. What will be the result of executing the following code?
Class A:
def __init__(self):
to pass
a = A (1)
print(hasattr(a, 'A'))
it will print false
will print 1
it will print true
will raise an exception
9. What will be the result of executing the following code?
class A:
def __str__(self):
returns 'a'
class B (A):
def __str__(self):
returns 'b'
class C (B):
to pass
o = C ()
print (or)
will raise an exception
a will be printed
it will print c
b will be printed
10. What will be the result of executing the following code?
class A:
to pass
class B (A):
to pass
class C (B):
to pass
print (issubclass (C, A))
will raise an exception
it will print true
1 will be printed
it will print false
11. What will be the result of executing the following code?
class A:
def a (self):
print ('a')
class B:
def a (self):
print('b')
class C (B, A):
def c (self):
self.a()
o = C ()
boss()
it will print c
it will print a
will raise an exception
it will print b
12. What will be the result of running the following code?
class A:
def __str__(self):
returns 'a'
class B (A):
def __str __ (self):
returns 'b'
class C (B):
to pass
o = C ()
print (o)
b will be printed
will raise an exception
it will print a
it will print c
13. What will be the result of executing the following code?
class A:
v=2
class B (A):
v=1
class C (B):
to pass
o = C ()
print (ov)
a blank line will be printed
it will print 2
will raise an exception
it will print 1
14. What will be the result of executing the following code?
def f (x):
to treat
x=x/x
except
print("a", end = ")
more
print ("b", end = ")
finally:
print ("c", end = " )
f (1)
f (0)
bcbc will be printed
bcac will be printed
it will print acac
an unhandled exception will be raised
15. What will be the result of executing the following code?
to treat
elevar Excepción (1,2,3)
except exception like e:
print(len([Link]))
it will print 2
it will print 1
will raise an unhandled exception
will print 3
16. What will be the result of executing the following code?
class Ex (Exception):
def __init __ (self, msg):
Exception .__ init __ (self, msg + msg)
[Link] = (msg,)
to treat
subir Ex ('ex')
except Ex like e:
print (e)
except exception as e:
print (e)
it will raise an unmanaged exception
a blank line will be printed
it will print exex
it will be printed ex
17. What will be the result of executing the following code?
class I:
def __init__(self):
self.s = 'abc'
self.i = 0
def __iter__ (auto):
return to oneself
def __next__(self):
If self.i == len(self.s):
raise StopIteration
v = self.s[self.i]
self.i += 1
to return
for x in I ():
print(x, end='')
cba will be printed
210 will be printed
012 will be printed
abc will be printed
18. What will be the result of executing the following code?
def I ():
abcdef
for c in s [:: 2]:
performance c
for x in I ():
print(x, end = '')
a blank line will be printed
bdf will be printed
abcdef will be printed
it will print ace
19. What will be the result of executing the following code?
def yo(n):
+
for i in the range (n):
s+=s
performance
for x in I (2):
print(x, end = '')
will be printed +
it will print +++
it will print ++++++
it will be printed ++
20. What will be the result of executing the following code?
def o (p):
def q ():
return '*' * p
return q
r = o (1)
s = o (2)
print (r () + s ())
it will be printed ***
it will be printed **
it will print ****
it will print *
21. When a file is opened in read mode, this:
it must exist (otherwise an exception will be generated)
it cannot exist (it has to be created each time)
it will be deleted if it exists
it does not need to exist (it will be created if absent)
22. If you want to open a text file in append mode,
I would use the following string in such a way:
t+a
a
a+t
in +
23. The [Link] sequence is typically associated with:
null device
keyboard
printer
screen
24. The strerror function comes from the system module
operational, and is designed to:
raise a string exception
translate an error description from one language to another
translate an error description into an error number
translate an error number in an error description
25. If s is an open stream in read mode, the following
line
q = [Link](1)
will be:
read 1 buffer from the sequence
read 1 kilobyte from the stream
read 1 character from the stream
read 1 line from the current
26. How does the readline() method react when it occurs?
the end of the file?
returns eof
returns -1
returns an empty string
raises an exception
27. The readlines() method returns:
list
dictionary
tuple
rope
28. Assuming that the invocation to open() has been
successfully executed, the following code fragment:
for x in open ('file', 'rt'):
print (x)
read the file line by line
read the file character by character
cause an exception
read the entire file at once
29. La clase de matriz de bytes puede crear objetos que
are designed for:
build matrices of 1 byte in size
convert tuples into lists
convert lists into tuples
Store organized amorphous data in bytes.
30. If you want to fill a byte array with read data
from a sequence, use the:
reading method ()
readinto() method
readfrom() method
readbytes() method