Quiz
Python I
Dieses Quiz hat ein Zeitlimit und öffnet sich deshalb im gewohnten Player.
Fragen in diesem Quiz (160)
1Question 1
What is the output of the following code if spam.py is run?
# spam.py
print("spam", end=' ')
import ham
# ham.py
import eggs
print("ham", end=' ')
# eggs.py
print("eggs", end=' '- ASyntax Error
- Bspam eggs ham
- Cspam ham
- Deggs ham spam
- Espam ham eggs
2Frage 1
What will be the value of the i variable when the while loop finishes its execution?
i = 0
while i != 0:
i = i - 1
else:
i = i + 1- A1
- B0
- C2
- Dthe variable becomes unavailable
3 Frage 41
Which of the following words can be used as a variable name? (Choose two.)- Afor
- BTrue
- Ctrue
- DFor
4Question 2
How do you call the function ham() saved as spam.py below?
def ham():
print("Hello World")- Aimport spam
ham() - Bimport spam.ham
ham() - Cimport spam
spam.ham() - Dfrom spam import ham
ham() - Eimport ham from spam
ham()
- Aimport spam
5Frage 2
Operator able to perform bitwise shifts is coded as (Choose two.)- A--
- B++
- C<<
- D>>
6 Frage 42
Python strings can be `glued` together using the operator:- A.
- B&
- C_
- D+
7QUESTION 8
What is the output of the following code?
math.ceil(-1.1)- A-1
- B-1.0
- C-2
- D-2.0
8Frage 3
What will the value of the i variable be when the following loop finishes its execution?
for i in range(10):
pass- A10
- Bthe variable becomes unavailable
- C11
- D9
9 Frage 43
A keyword (Choose two.)- Acan be used as an identifier
- Bis defined by Python's lexis
- Cis also known as a reserved word
- Dcannot be used in the user's code
10QUESTION 9
What is the output of the following code?
math.floor(-1.1)- A-1
- B-1.0
- C-2
- D-2.0
11 Frage 4
The following expression
1+-2
is:- Aequal to 1
- Binvalid
- Cequal to 2
- Dequal to -1
12Frage 44
How many stars (*) does the snippet print?
s = '*****'
s = s - s[2]
print(s)- Athe code is erroneous
- Bfive
- Cfour
- Dtwo
13QUESTION 10
What is the output of the following code?
math.trunc(-1.1)- A-1
- B-1.0
- C-2
- D-2.0
14 Frage 5
A compiler is a program designed to (Choose two.)- Arearrange the source code to make it clearer
- Bcheck the source code in order to see of it's correct
- Cexecute the source code
- Dtranslate the source code into machine code
15Frage 45
Which line can be used instead of the comment to cause the snippet to produce the following expected
output? (Choose two.)
Expected output:
1 2 3
Code:
c, b, a = 1, 3, 2
# put line here
print(a, b, c)- Ac, b, a = b, a, c
- Bc, b, a = a, c, b
- Ca, b, c = c, a, b
- Da, b, c = a, b, c
16QUESTION 11
What is the output of the following code?
math.factorial(3.0))- A6
- B6.0
- CTypeError: 'float' object cannot be interpreted as an integer
- DTypeError: factorial() takes 2 arguments
17 Frage 6
What is the output of the following piece of code?
a = 'ant'
b = "bat"
c = 'camel'
print(a, b, c, sep='"') # '+"+ '- Aant'bat'camel
- Bant"bat"camel
- Cantbatcamel
- Dprint(a, b, c, sep= '"')
18Frage 46
Assuming that the V variable holds an integer value to 2, which of the following operators should be used
instead of OPER to make the expression equal to 1?
V OPER 1- A<<<
- B>>>
- C>>
- D<<
19QUESTION 12
What is the output of the following code?
math.factorial(-3)- A-6
- B-6.0
- CTypeError: type float doesn't define __factorial__ method
- DValueError: factorial() not defined for negative values
20Frage 7
What is the expected output of the following snippet?
i = 5
while i > 0:
i = i // 2
if i % 2 = 0:
break
else:
i += 1
print(i)- Athe code is erroneous
- B3
- C7
- D15
21 Frage 47
How many stars (*) does the following snippet print?
i = 3
while i > 0:
i -= 1
print("*")
else:
print("*")- Athe code is erroneous
- Bfive
- Cthree
- Dfour
22QUESTION 13
What is the output of the following code?
math.hypot(2)- A3.6055512754639896
- B2.0
- CTypeError: type int doesn't define __hypot__ method
- DTypeError: hypot() takes 2 arguments
23 Frage 8
How many lines does the following snippet output?
for i in range(1, 3):
print("*", end="")
else:
print("*")- Athree
- Bone
- Ctwo
- Dfour
24Frage 48
UNICODE is:- Athe name of an operating system
- Ba standard for encoding and handling texts
- Cthe name of a programming language
- Dthe name of a text processor
25QUESTION 14
What is the output of the following code?
math.sqrt(1)- A0.5
- B1
- C1.0
- DTypeError: type int doesn't define __sqrt__ method
26Frage 9
Which of the following literals reflect the value given as 34.23? (Choose two.)- A.3423e2
- B3423e-2
- C.3423e-2
- D3423e2
27 Frage 49
What is the expected output of the following snippet?
s = '*-*'
s = 2 * s + s * 2
print(s)- A*-**-**-**-*
- B*-**-**-**-**-**-**-**-*
- C*-*
- D*-**-*
28Question 15
Select all option(s) which returns a random floating number between 0 and 1?- Amath.random()
- Bmath.random(1.0)
- Crandom.random()
- Drandom.random(1.0)
29 Frage 10
What is the expected output of the following snippet?
a = 2
if a > 0:
a += 1
else:
a -= 1
print(a)- A3
- B1
- C2
- Dthe code is erroneous
30 Frage 50
Which of the listed actions can be applied to the following tuple? (Choose two.)
tup = ()- Atup[:]
- Btup.append(0)
- Ctup[0]
- Ddel tup
31Question 16
Select all option(s) which returns a random number between 0 and 100?- Arandom.random(100)
- Brandom.random(0, 100)
- Crandom.random()*100
- Drandom.random(100.0)
32Frage 11
Assuming that the following snippet has been successfully executed, which of the equations are True?
(Choose two.)
a = [1]
b = a
a[0] = 0- Alen(a) == len(b)
- Bb[0] +1 == a[0]
- Ca[0] == b[0]
- Da[0] + 1 == b[0]
33Frage 51
Executing the following snippet
dct = {'pi': 3.14}
dct['pi'] = 3.1415- Ato hold two keys named 'pi' linked to 3.14 and 3.1415 respectively
- Bto hold two key named 'pi' linked to 3.14 and 3.1415
- Cto hold one key named 'pi' linked to 3.1415
- Dto hold two keys named 'pi' linked to 3.1415
34QUESTION 17
What can be the possible output of the following code?
random.seed(10, 2)
print(random.random())- A3.6055512754639896
- B0.5714025946899135
- CAttributeError: module 'random' has no attribute 'seed'
- DTypeError: seed() takes 1 argument
35 Frage 12
Assuming that the following snippet has been successfully executed, which of the equations are False?
(Choose two.)
a = [0]
b = a[:]
a[0] = 1- Alen(a) == len(b)
- Ba[0] - 1 == b[0]
- Ca[0] == b[0]
- Db[0] - 1 == a[0]
36 Frage 52
How many elements will the list1 list contain after execution of the following snippet?
list1 = "don't think twice, do it!".split(',')- Atwo
- Bzero
- Cone
- Dthree
37QUESTION 18
Select all option(s) to properly call the choice() and/or choices() function?- Arandom.choice("spam", "ham", "eggs")
- Brandom.choice(["spam", "ham", "eggs"])
- Crandom.choice({"spam", "ham", "eggs"})
- Drandom.choices(["spam", "ham", "eggs"])
- Erandom.choices(["spam", "ham", "eggs"], weights = [10, 1, 1], k = 14)
38Frage 13
Which of the following statements are true? (Choose two.)- APython strings are actually lists
- BPython strings can be concatenated
- CPython strings can be sliced like lists
- DPython strings are mutable
39 Frage 53
Which of the equations are True? (Choose two.)- Achr(ord(x)) == x
- Bord(ord(x)) == x
- Cchr(chr(x)) == x
- Dord(chr(x)) == x
40QUESTION 19
What can be the possible output of the following code?
random.sample(["spam", "ham", "eggs"], k = 1)- Aspam
- B['spam']
- CTypeError: sample() got an unexpected keyword argument 'k'
- DTypeError: sample() takes 1 argument
41 Frage 14
Which of the following sentences are true? (Choose two.)- ALists may not be stored inside tuples
- BTuples may be stored inside lists
- CTuples may not be stored inside tuples
- DLists may be stored inside lists
42 Frage 54
If you want to transform a string into a list of words, what invocation would you use? (Choose two.)
Expected output:
The, Catcher, in, the, Rye,
Code:
s = "The Catcher in the Rye"
l = # put a proper invocation here
for w in l:
print(w, end=', ') # outputs: The, Catcher, in, the, Rye,- As.split()
- Bsplit(s, ' ')
- Cs.split(' ')
- Dsplit(s)
43QUESTION 26
What is the datatype of the return value of the function platform.version()?- Aint
- Bfloat
- Cstr
- Darray
44 Frage 15
Assuming that String is six or more letters long, the following slice
string[1:-2]
is shorter than the original string by:- Afour chars
- Bthree chars
- Cone chars
- Dtwo chars
45 Frage 55
Assuming that lst - is a four-element list.
Is there any difference between these two statements?
del lst # the first line
del lst[:] # the second line- Ayes, there is, the first line empties the list, the second line deletes the list as a whole
- Byes, there is, the first line deletes the list as a whole, the second line just empties the list
- Cno, there is no difference
- Dyes, there is, the first line deletes the list as a whole, the second line removes all the elements except
the first one
46QUESTION 31
The extension of a compiled bytecode of the Python source file is- A.py
- B.pyc
- C.__pycache__
- DPython is an interpreted language hence it does not compile the source file
47Frage 16
What is the expected output of the following snippet?
lst = [1, 2, 3, 4]
lst = lst[-3:-2]
lst = lst[-1]
print(lst)- A1
- B4
- C2
- D3
48 Frage 56
What should you put instead of XXX to print out the module name?
if __name__ != "XXX":
print(__name__)- Amain
- B_main_
- C__main__
- D___main___
49QUESTION 33
How should you write the variable spam to inform a module user that it should not be accessed directly?- Aspam since all variables in modules are considered private
- B_spam
- C__spam
- DSPAM
50Frage 17
What is the expected output of the following snippet?
s = 'abc'
for i in len(s):
s[i] = s[i].upper()
print(s)- Aabc
- BThe code will cause a runtime exception
- CABC
- D123
51 Frage 57
Files with the suffix.pyc contain:- APython 4 source code
- Bbackups
- Ctemporary data
- Dsemi-compiled Python code
52QUESTION 34
Select all valid option(s) about __init__.py- A__init__.py is contained in regular packages
- B__init__.py is contained in namespace packages
- C__init__.py is automatically executed when the regular package is imported.
- D__init__.py is automatically executed when the namespace package is imported
53 Frage 18
How many elements will the list2 list contain after execution of the following snippet?
list1 = [False for i in range(1, 10)]
list2 = list1[-1:1:-1]- Azero
- Bfive
- Cseven
- Dthree
54Frage 58
Package source directories/folders can be:- Aconverted into the so-called pypck format
- Bpacked as a ZIP file and distributed as one file
- Crebuilt to a flat form and distributed as one directory/folder
- Dremoved as Python compiles them into an internal portable format
55QUESTION 35
What directories are searched by the interpreter for spam.py given the code below?
import spam
print(spam.ham)
print(spam.eggs)- ADirectory where spam.py was run
- BCurrent directory if the interpreter is run interactively
- CList of directories contained in PATH environment variable
- DList of directories contained in PYTHONPATH environment variable
- EPython installation-dependent directories configured during installation
- FList of directories in sys.path
56 Frage 19
What would you used instead of XXX if you want to check eather a certain 'key' exists in a dictionary called
dict? (Choose two.)
if XXX:
print("Key exists")- A'key' in dict
- Bdict['key'] != None
- Cdict.exists('key')
- D'key' in dict.keys( )
57Frage 59
What can you deduce from the line below? (Choose two.)
x = a.b.c.f()- Aimport a.b.c should be placed before that line
- Bf() is located in module c of subpackage b of package a
- Cthe line is incorrect
- Dthe function being invoked is called a.b.c.f()
58QUESTION 36
What is the output of the following code?
try:
abcd
efgh
except:
pass- ANo output
- BSyntaxError: invalid syntax
- CNameError: name 'UndefinedException' is not defined
- DAdd () on Line 2 and 3 to fix the syntax error
59 Frage 20
You need data which can act as a simple telephone directory.
You can obtain it with the following clauses (Choose two.)
(assume that no other items have been created before)- Adir={'Mom': 5551234567, 'Dad': 5557654321}
- Bdir= {'Mom': '5551234567', 'Dad': '5557654321'}
- Cdir= {Mom: 5551234567, Dad: 5557654321}
- Ddir= {Mom: '5551234567', Dad: '5557654321'}
60 Frage 60
A two-parameter lambda function raising its first parameter to the power of the second parameter should
be declared as:- Alambda (x, y) = x ** y
- Blambda (x, y): x ** y
- Cdef lambda (x, y): return x ** y
- Dlambda x, y: x ** y
61QUESTION 37
What is the output of the following code?
try:
raise OSError
finally:
pass- ANo output
- BOSError
- CNameError: name 'OSError' is not defined
- DSyntaxError: invalid syntax
62Frage 21
Can a module run like regular code?- Ayes, and it can differentiate its behavior between the regular launch and import
- Bit depends on the Python version
- Cyes, but in cannot differentiate its behavior between the regular launch and import
- Dno, it is not possible; a module can be imported, not run
63 Frage 61
What is the expected output of the following code?
def f(n):
if n == 1:
return 1
return n + f(n - 1)
print(f(2))- A21
- B12
- C3
- DNone
64QUESTION 38
What is the output of the following code?
try:
raise ValueError
except TypeError, ValueError:
raise- ANo output
- BTypeError
- CValueError
- DSyntaxError: invalid syntax
65Frage 22
Select the valid fun() invocations: (Choose two.)
def fun(a, b=0):
return a * b
- Afun(b=1)
- Bfun(a=0)
- Cfun(b=1, 0)
- Dfun(1)
66 Frage 62
A method for passing the arguments used by the following snippet is called:
def fun(a, b):
return a + b
res = fun(1, 2)
A.
B.- Asequential
- Bnamed
- Cpositional
- Dkeyword
67QUESTION 39
What will happen if spam.py is run?
# spam.py
try:
print(x)
except:
print("An exception occurred")- Athe script will run but will not print anything
- BNone will be printed
- CAn exception occurred will printed
- DCompile time error
68Frage 23
A file name like this one below says that: (Choose three.)
services.cpython-36.pyc- Athe interpreter used to generate the file is version 3.6
- Bit has been produced by CPython
- Cit is the 36 version of the file
- Dthe file comes from the services.py source file
69Frage 63
What is the expected behavior of the following code?
def f(n):
for i in range(1, n + 1):
yield i
for i in f(2):
print(i, end=' ')- Aprint 2 1
- Bprint 1 2
- Ccause a runtime exception
- Dprint <generator object f at (some hex digits)>
70QUESTION 40
What is the output of the following code?
def this_fails():
x = 1/0
try:
this_fails()
except ZeroDivisionError:
pass- ANo output
- BSyntaxError: invalid syntax
- CZeroDivisionError: division by zero
- DNameError: name 'ZeroDivisionError' is not defined
71Frage 24
What is the expected behavior of the following snippet?
def a(x, y):
return x[y]
print(a(0, [1]))- Acause a runtime exception
- Bprint 1
- Cprint 0,[1]
- Dprint [1]
72 Frage 64
What is the expected output of the following code?
lst = [x for x in range(5)]
lst = list(filter(lambda x: x % 2 == 0, lst))
print(len(lst))- A2
- BThe code will cause a runtime exception
- C1
- D3
73QUESTION 42
What is the output of the following code?
try:
print("1", end='')
raise Exception
print("2", end='')
except BaseException:
print("3", end='')
else:
print("4", end='')
finally:
print("5")- ANameError: name 'BaseException' is not defined
- B1235
- C1245
- D135
- E145
74 Frage 25
What can you do if you don't like a long package path like this one?
import alpha.beta.gamma.delta.epsilon.zeta- Ayou can make an alias for the name using the alias keyword
- Bnothing, you need to come to terms with it
- Cyou can shorten it to alpha . zeta and Python will find the proper connection
- Dyou can make an alias for the name using the as keyword
75 Frage 65
What is the expected behavior of the following code?
def unclear(x):
if x % 2 == 1:
return 0
print(unclear(1) + unclear(2))- Aprints 0
- Bcause a runtime exception
- Cprints 3
- Dprint an empty line
76QUESTION 45
If there are more than 1 except clause, what happens after a try clause executes?- ANone of the except is executed
- BAt least 1 except is executed
- CNot more than 1 except is executed
- DExactly 1 of the except is executed
77 Frage 26
What is the expected output of the following code?
str = 'abcdef'
def fun(s):
del s[2]
return s
print(fun(str))- Aabcef
- BThe program will cause a runtime exception/error
- Cacdef
- Dabdef
78Frage 66
If any of a class's components has a name that starts with two underscores (___), then:- Athe class component's name will be mangled
- Bthe class component has to be an instance variable
- Cthe class component has to be a class variable
- Dthe class component has to be a method
79QUESTION 46
Which of the statements below is valid?- AThe finally branch in a try block is always executed.
- BThe finally branch in a try block will only be executed if an exception occurs.
- CThe finally branch in a try block will only be executed if the exception did not occur
- DThe finally branch in a try block is optional
- EThe finally branch in a try block is required because it is always executed.
80 Frage 27
What is the expected output of the following code?
def f(n):
if n == 1:
return '1'
return str(n) + f(n - 1)
print(f(2))
- A21
- B2
- C3
- D12
81 Frage 67
If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:- Aexcept Ex1 Ex2:
- Bexcept (Ex1, Ex2):
- Cexcept Ex1, Ex2:
- Dexcept Ex1+Ex2:
82What is the output of the following code?
class Spam(Exception):
pass
class Ham(Spam):
pass
for cls in [Spam, Ham]:
try:
raise cls()
except Spam:
print("Spam", end=" ")
except Ham:
print("Ham", end=" ")- ASpam Ham
- BSpam Spam
- CSpam Ham Spam Ham
- DInvalid Syntax
83 Frage 28
What is the expected behavior of the following snippet?
def x(): # line 01
return 2 # line 02
x = 1 + x() # line 03
print(x) # line 04- Acause a runtime exception on line 02
- Bcause a runtime exception on line 01
- Ccause a runtime exception on line 03
- Dprint 3
84 Frage 68
A function called issubclass(c1, c2) is able to check if:- Ac1 and c2 are both subclasses of the same superclass
- Bc2 is a subclass of c1
- Cc1 is a subclass of c2
- Dc1 and c2 are not subclasses of the same superclass
85QUESTION 48
Which option are valid replacements for the marker in the given code?
try:
x = 1/0
<<< INSERT CODE HERE >>>
pass- Aexcept BaseException:
- Bexcept Exception:
- Cexcept MathError:
- Dexcept ArithmeticException:
- Eexcept ArithmeticError:
- Fexcept DivisionZeroError:
- Gexcept ZeroDivisionError:
86 Frage 29
What is the expected behavior of the following code?
def f(n):
for i in range(1, n + 1):
yield i
print(f(2))- Aprint 4321
- Bprint <generator object f at (some hex digits)>
- Ccause a runtime exception
- Dprint 1234
87Frage 69
A class constructor (Choose two.)- Acan return a value
- Bcannot be invoked directly from inside the class
- Ccan be invoked directly from any of the subclasses
- Dcan be invoked directly from any of the superclasses
88QUESTION 49
What is the output of the following code if spam.txt does not exist?
import sys
try:
f = open('spam.txt')
s = f.readline()
except:
raise- Athe script will run but will not print anything
- B"None" will be printed
- CFileNotFoundError: [Errno 2] No such file or directory: 'spam.txt'
- DCompile time error
89 Frage 30
If you need a function that does nothing, what would you use instead of XXX? (Choose two.)
def idler():
XXXX- Apass
- Breturn
- Cexit
- DNone
90 Frage 70
The following class definition is given.
We want the show() method to invoke the get() method, and then output the value the get() method returns.
Which of the invocations should be used instead of XXX?
class Class:
def __init__(self, val):
self.val = val
def get(self):
return self.val
def show(self):
XXX- Aprint(get(self))
- Bprint(self.get())
- Cprint(get())
- Dprint(self.get(val))
91QUESTION 50
Select which option will call the __init__ method of Exception based on the code below.
class SpamException(Exception):
def __init__(self, message):
<<< INSERT CODE HERE >>>
self.message = message
raise SpamException("Spam")- Asuper().__init__(message)
- BException.__init__(self, message)
- Csuper(SpamException, self).__init__(message)
- Dsuper.__init__(message)
92 Frage 31
Is it possible to safely check if a class/object has a certain attribute?- Ayes, by using the hasattr attribute
- Byes, by using the hasattr( ) method
- Cyes, by using the hasattr( ) function
- Dno, it is not possible
93 Frage 71
If s is a stream open for reading, what do you expect from the following invocation?
c = s.read()- Aone line of the file will be read and stored in the string called c
- Bthe whole file content will be read and stored in the string called c
- Cone character will be read and stored in the string called c
- Done disk sector (512 bytes) will be read and stored in the string called c
94QUESTION 51
What is the output of the following code?
try:
raise UndefinedException
except:
pass- ANo output
- BSyntaxError: invalid syntax
- CNameError: name 'UndefinedException' is not defined
- DAdd () on Line 2 to fix the syntax error
95 Frage 32
The first parameter of each method:- Aholds a reference to the currently processed object
- Bis always set to None
- Cis set to a unique random value
- Dis set by the first argument's value
96 Frage 72
You are going to read 16 bytes from a binary file into a bytearray called data.
Which lines would you use?
(Choose two.)- Adata = bytearray(16); bf.readinto(data)
- Bdata = binfile.read(bytearray(16))
- Cbf.readinto(data = bytearray(16))
- Ddata = bytearray(binfile.read(16))
97QUESTION 52
What is the output of the following code?
try:
raise UndefinedException
except NameError:
print('NameError')
except UndefinedException:
print('UndefinedException')
except:
pass- ANo output
- BNameError
- CUndefinedException
- DSyntaxError: invalid syntax
98 Frage 33
The simplest possible class definition in Python can be expressed as:- Aclass X:
- Bclass X: pass
- Cclass X: return
- Dclass X: { }
99 Frage 73
What is the expected output of the following snippet?
class X:
pass
class Y(X):
pass
class Z(X):
pass
x = Z()
z = Z()
print(isinstance(x, Z), isinstance(z, X))- ATrue False
- BTrue True
- CFalse False
- DFalse True
100QUESTION 53
What is the output of the following code?
try:
raise IOError
except IOError:
raise RuntimeError from None- ANo output
- BIOError
- CRuntimeError
- DSyntaxError: invalid syntax
101 Frage 34
If you want to access an exception object's components and store them in an object called e, you have to
use the following form of exception statement:- Aexcept Exception(e):
- Bexcept e = Exception:
- Cexcept Exception as e:
- Dsuch an action is not possible in Python
102 Frage 74
Assuming that the code below has been executed successfully, which of the following expressions will
always evaluate to True? (Choose two.)
import random
random.seed(1)
v1 = random.random()
random.seed(1)
v2 = random.random()- Av1 >= 1
- Bv1 == v2
- Clen(random.sample([1, 2, 3], 2)) > 2
- Drandom.choice([1, 2, 3]) >= 1
103QUESTION 54
What is the output of the following code?
try:
raise IOError
except IOError as e:
raise RuntimeError from e- ANo output
- BTypeError
- CRuntimeError
- DSyntaxError: invalid syntax
104Frage 35
A variable stored separately in every object is called:
A.
B.
C.
D.- Athere are no such variables, all variables are shared among objects
- Ba class variable
- Can object variable
- Dan instance variable
105 Frage 75
Which one of the platform module functions should be used to determine the underlying platform name?- Aplatform.python_version()
- Bplatform.processor()
- Cplatform.platform()
- Dplatform.uname()
106QUESTION 55
Which of the statements below is valid?
spam = 0
assert spam == 0
A.
B.
C.
D.- AAssertionError will be triggered because the expression is True
- BNo AssertionError will be triggered since the expression is True
- CMissing parentheses in call to assert error will be displayed
- DThe word True will be printed on screen
107 Frage 36
There is a stream named s open for writing. What option will you select to write a line to the stream?
A.
B.
C.
D.- As.write("Hello\n")
- Bwrite(s, "Hello")
- Cs.writeln("Hello")
- Ds.writeline("Hello")
108 Frage 76
What is the expected output of the following code?
import sys
import math
b1 = type(dir(math)[0]) is str
b2 = type(dir(sys.path)[-1]) is str
print(b1 and b2)- AFalse
- BNone
- CTrue
- D0
109QUESTION 56
What is the result of the following code?
>>> assert (False, 'Trigger Assertion')- ANo output
- BTrigger Assertion
- CSyntaxError: invalid syntax
- DAssertion is always true
110 Frage 37
You are going to read just one character from a stream called s.
Which statement would you use?- Ach = read(s, 1)
- Bch = s.input(1)
- Cch = input(s, 1)
- Dch = s.read(1)
111 Frage 77
With regards to the directory structure below, select the proper forms of the directives in order to import
module_a. (Choose two.)
pypack (dir)
|
|-- upper (dir)
| |
| |-- lower (dir)
| | |
| | |_ module_c.py (file)
| |
| |_ module_b.py (file)
|
|_ module_a.py (file)- Afrom pypack import module_a
- Bimport module_a from pypack
- Cimport module_a
- Dimport pypack.module_a
112QUESTION 57
Which option(s) are valid except clause for ZeroDivisionError to be accessed as variable e?- Aexcept ZeroDivisionError as e:
- Bexcept ZeroDivisionError(e):
- Cexcept (ZeroDivisionError) as e:
- Dexcept ZeroDivisionError e:
- Eexcept (ZeroDivisionError as e):
113Frage 38
What can you deduce from the following statement? (Choose two.)
str = open('file.txt', 'rt')- Astr is a string read in from the file named file.txt
- Ba newline character translation will be performed during the reads
- Cif file. txt does not exist, it will be created
- Dthe opened file cannot be written with the use of the str variable
114 Frage 78
A Python module named pymod.py contains a function named pyfun().
Which of the following snippets will let you invoke the function? (Choose two.)- Aimport pymod
pymod.pyfun() - Bfrom pymod import pyfun
pyfun() - Cfrom pymod import *
pymod.pyfun() - Dimport pyfun from pymod
pyfun()
- Aimport pymod
115 QUESTION 58
What is the output of the following code?
try:
a = 1/'0'
except (ZeroDivisionError, TypeError) as e:
print(type(e))- AThe script will run but will not print anything
- B<class 'ZeroDivisionError'>
- C<class 'TypeError'>
- DInvalid Syntax
116 Frage 39
The following class hierarchy is given. What is the expected out of the code?
class A:
def a(self):
print("A", end=' ')
def b(self):
self.a()
class B(A):
def a(self):
print("B", end=' ')
def do(self):
self.b()
class C(A):
def a(self):
print("C", end=' ')
def do(self):
self.b()
B().do()
C().do()
A. B B
B. C C
C. A A
D. B C- AB B
- BC C
- CA A
- DB C
117 Frage 79
What is true about Python packages? (Choose two.)- Aa package is a single file whose name ends with the pa extension
- Ba package is a group of related modules
- Cthe __name__ variable always contains the name of a package
- Dthe pyc extension is used to mark semi-compiled Python packages
118 QUESTION 59
Which option will print ('spam', 'eggs') based on the following code?
try:
raise Exception('spam', 'eggs')
except Exception as exception:
<<< INSERT CODE HERE >>>- Aprint(exception.params)
- Bprint(exception)
- Cprint(exception.args)
- Dprint(exception.iterable[:])
119 Frage 40
Python's built in function named open() tries to open a file and returns:
- Aan integer value identifying an opened file
- Ban error code (0 means success)
- Ca stream object
- Dalways None
120 Frage 80
What is the expected behavior of the following code?
m = 0
def foo(n):
global m
assert m == 0
try:
return 1 / n
except ArithmeticError:
m += 1
raise
try:
foo(0)
except ArithmeticError:
m += 2
except:
m += 1
print(m)- Ait outputs 3
- Bit outputs 1
- Cthe code is erroneous and it will not execute
- Dit outputs 2
121Frage 81
What is the expected behavior of the following code?
s = '2A'
try:
n = int(s)
except TypeError:
n = 3
except LookupError:
n = 2
except:
n = 1
print(n)- Ait outputs 3
- Bthe code is erroneous and it will not execute
- Cit outputs 1
- Dit outputs 2
122 Frage 82
Which of the following snippets will execute without raising any unhandled exceptions? (Choose two.)- Atry:
print(0/0)
except:
print(0/1)
else:
print(0/2) - Btry:
print(int("0"))
except NameError:
print("0")
else:
print(int("")) - Cimport math
try:
print(math.sqrt(-1))
except:
print(math.sqrt(0))
else:
print(math.sqrt(1)) - Dtry:
print(float("1e1"))
except (NameError, SystemError):
print(float("1a1"))
else:
print(float("1c1"))
- Atry:
123 Frage 83
What is the expected behavior of the following code?
my_list = [1, 2, 3]
try:
my_list[3] = my_list[2]
except BaseException as error:
print(error)- Ait outputs error
- Bit outputs <class 'IndexError'>
- Cit outputs list assignment index out of range
- Dthe code is erroneous and it will not execute
124 Frage 84
What is true about the following snippet? (Choose two.)
class E(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return "it's nice to see you"
try:
print("I feel fine")
raise Exception("what a pity")
except E as e:
print(e)
else:
print("the schow must go on")- Athe string it's nice to see you will be seen
- Bthe string I feel fine will be seen
- Cthe code will raise an unhandled exception
- Dthe string what a pity will be seen
125Frage 85
Which of the following expressions evaluate to True? (Choose two.)- Aord("Z") - ord("z") == ord("0")
- Bchr(ord('A') + 1) == 'B'
- Clen('\'') == 1 # ( ' \ ' ' )
- Dlen(""" """) == 0
126 Frage 86
Which of the following invocations are valid? (Choose two.)- A"python".sort()
- Bsorted("python")
- Crfind("python", "r")
- D"python".index("th")
127 Frage 87
What is the expected behavior of the following code?
string = str(1 / 3)
dummy = ''
for character in string:
dummy = character + dummy
print(dummy[-1])- Ait raises an exception
- Bit outputs 0
- Cit outputs 3
- Dit outputs 'None'
128 Frage 88
Which of the following statements are true? (Choose two.)- AII in ASCII stands for Information Interchange
- Ba code point is a number assigned to a given character
- CACII is synonymous with UTF-8
- D\e is an escape sequence used to mark the end of lines
129 Frage 89
Which of the following expressions evaluate to True? (Choose two.)- Astr(1-1) in '0123456789'
- B'dcb' not in 'abcde'[::-1]
- C'phd' in 'alpha'
- D'True' not in 'False'
130 Frage 90
What is the expected behavior of the following code?
the_list = "alpha;beta;gamma".split(":")
the_string = ''.join(the_list)
print(the_string.isalpha())- Ait raises an exception
- Bit outputs True
- Cit outputs False
- Dit outputs nothing
131Frage 91
Which of the following expressions evaluate to True? (Choose two.)- A121 + 1 != '1' + 2 * '2'
- B'1' + '1' + '1' < '1' * 3
- C'AbC'.lower() < 'AB'
- D'3.14' != str(3.1415)
132Frage 92
Assuming that the snippet below has been executed successfully, which of the following expressions
evaluate to True?
string = 'python'[::2]
string = string[-1] + string[-2]- Astring[0] == 'o'
- Bstring is None
- Clen(string) == 3
- Dstring[0] == string [-1]
133Frage 93
What is the expected behavior of the following code?
class Super:
def make(self):
return 0
def doit(self):
return self.make()
class Sub_A(Super):
def make(self):
return 1
class Sub_B(Super):
pass
a = Sub_A()
b = Sub_B()
print(a.doit() + b.doit())- Ait outputs 0
- Bit outputs 1
- Cit raises an exception
- Dit outputs 2
134Frage 94
Assuming that the following inheritance set is in force, which of the following classes are declared properly? (Choose two.)
class A:
pass
class B(A):
pass
class C(A):
pass
class D(B):
pass- Aclass Class_4(D, A):
pass - Bclass Class_3(A, C):
pass - Cclass Class_2(B, D):
pass - Dclass Class_1(C, D):
pass
- Aclass Class_4(D, A):
135 Frage 95
What is the expected output of the following snippet?
class Upper:
def method(self):
return 'upper'
class Lower(Upper):
def method(self):
return 'lower'
Object = Upper()
print(isinstance(Object, Lower), end=' ')
print(Object.method())- ATrue upper
- BTrue lower
- CFalse upper
- DFalse lower
136 Frage 96
Assuming that the code below has been placed inside a file named code.py and executed successfully,
which of the following expressions evaluate to True? (Choose two.)
class ClassA:
var = 1
def __init__(self, prop):
prop1 = prop2 = prop
def __str__(self):
return 'Object'
class ClassB(ClassA):
def __init__(self, prop):
prop3 = prop ** 2
super().__init__(prop)
Object = ClassB(2)- Alen(ClassA.__bases__) == 2
- BClassA.__module__ == '__main__'
- C__name__ == 'code.py'
- Dstr(Object) == 'Object'
137 Frage 97
What is the expected behavior of the following code?
class Class:
__Var = 0
def foo(self):
Class._Class__Var += 1
self.__prop = Class._Class__Var
o1 = Class()
o1.foo()
o2 = Class()
o2.foo()
print(o2._Class__Var + o1._Class__prop)- Ait outputs 1
- Bit outputs 3
- Cit outputs 6
- Dit raises an exception
138 Frage 98
What is the expected behavior of the following code?
class Class:
Variable = 0
def __init__(self):
self.value = 0
object_1 = Class()
object_1.Variable = 1
object_2 = Class()
object_2.value += 1
print(object_2.Variable + object_1.value)- Ait outputs 0
- Bit raises an exception
- Cit outputs 1
- Dit outputs 2
139 Frage 99
What is true about Object-Oriented Programming in Python? (Choose two.)- Aeach object of the same class can have a different set of methods
- Ba subclass is usually more specialized than its superclass
- Cif a real-life object can be described with a set of adjectives, they may reflect a Python object method
- Dthe same class can be used many times to build a number of objects
140 Frage 100
What is true about Python class constructors? (Choose two.)- Athere can be more than one constructor in a Python class
- Bthe constructor must return a value other than None
- Cthe constructor is a method named __init__
- Dthe constructor must have at least one parameter
141 Frage 101
Assuming that the following piece of code has been executed successfully, which of the expressions
evaluate to True? (Choose two.)
class A:
VarA = 1
def __init__(self):
self.prop_a = 1
class B(A):
VarA = 2
def __init__(self):
super().__init__()
self.prop_b = 2
obj_a = A()
obj_aa = A()
obj_b = B()
obj_bb = obj_b- Aisinstance(obj_a, A)
- BA.VarA == 1
- Cobj_a is obj_aa
- DB.VarA == 1
142 Frage 102
Assuming that the code below has been executed successfully, which of the expressions evaluate to True?
(Choose two.)
class Class:
var = data = 1
def __init__(self, value):
self.prop = value
Object = Class(2)- Alen(Class.__dict__) == 1
- B'data' in Class.__dict__
- C'var' in Class.__dict__
- D'data' in Object.__dict__
143 Frage 103
A property that stores information about a given class's super-classes is named:- A__upper__
- B__super__
- C__ancestors__
- D__bases__
144 Frage 104
Which of the following lines of code will work flawlessly when put independently inside the add_new()
method in order to make the snippet's output equal to [0, 1, 2]? (Choose two.)
class MyClass:
def __init__(self, size):
self.queue = [i for i in range(size)]
def get(self):
return self.queue
def get_last(self):
return self.queue[-1]
def add_new(self):
# insert the line of the code here
Object = MyClass(2)
Object.add_new()
print(Object.get())- Aself.queue.append(self.get_last() + 1)
- Bself.queue.append(get_last() + 1)
- Cself.queue.append(self.queue[-1] + 1)
- Dqueue.append(self.get_last() + 1)
145 Frage 105
What is the expected output of the following code?
mytu = ('a', 'b', 'c')
m = tuple(map(lambda x: chr(ord(x) + 1), mytu))
print(m[-2])- Aa
- Bc
- Can exception is raised
- Db
146 Frage 106
What is the expected output of the following code if there is no file named non_existing_file inside the
working directory?
try:
f = open('non_existing_file', 'w')
print(1, end=' ')
s = f.readline()
print(2, end=' ')
except IOError as error:
print(3, end=' ')
else:
f.close()
print(4, end=' ')- A1 2 4
- B1 2 3 4
- C2 4
- D1 3
147 Frage 107
What is the expected output of the following code if the file named existing_text_file is a non-zero length
text file located inside the working directory?
try:
f = open('existing_text_file', 'w')
d = f.readline()
print(len(d))
f.close()
except IOError:
print(-1)- Athe length of the first line from the file
- B-1
- Cthe number of lines contained inside the file
- Dthe length of the last line from the file
148 Frage 108
What is the expected behavior of the following code?
my_list = [i for i in range(5)]
m = [my_list[i] for i in range(4, 0, -1) if my_list[i] % 2 != 0]
print(m)- Ait outputs [1, 3]
- Bthe code is erroneous and it will not execute
- Cit outputs [3, 1]
- Dit outputs [4, 2, 0]
149 Frage 109
Assuming that the following code has been executed successfully, which of the expressions evaluate to
True? (Choose two.)
def f(x, y):
nom, denom = x, y
def g():
return nom / denom
return g
a = f(1, 2)
b = f(3, 4)- Ab() == 4
- Ba != b
- Ca is not None
- Da() == 4
150Frage 110
What is the expected output of the following code?
def foo(x, y):
return y(x) + (x + 1)
print(foo(1, lambda x: x*x))- A3
- B5
- C4
- Dan exception is raised
151 Frage 111
Which of the following lambda definitions are correct? (Choose two.)- Alambda x,y: (x,y)
- Blambda x,y: return x//y - x%y
- Clambda x,y: x//y - x%y
- Dlambda x,y = x//y - x%y
152 Frage 112
Which of the following statements are true? (Choose two.)- Aif invoking open () fails, an exception is raised
- Bopen () requires a second argument
- Copen () is a function which returns an object that represents a physical file
- Dinstd, outstd. errstd are the names of pre-opened streams
153Frage 113
What is the expected behavior of the following code?
x = 3 % 1
y = 1 if x > 0 else 0
print(y)- Athe code is erroneous and it will not execute
- Bit outputs 1
- Cit outputs -1
- Dit outputs 0
154Frage 114
Which of the following snippets will execute without raising any unhandled exceptions? (Choose two).- Atry:
print(float("1e1"))
except (ValueError, NameError):
print(float("1a1"))
else:
print(float("101")) - Btry:
print(1/1)
except:
print(2/1)
else:
print(3/0) - Ctry:
print(1/0)
except ValueError:
print(1/1)
else:
print(1/2) - Dtry:
print(0/1)
except:
print(1/1)
else:
print(2/1)
- Atry:
155 Frage 115
Which of the following expressions evaluate to True? (Choose two.)- A'8' + '8' != 2 * '8'
- B'xYz'.lower() > 'XY'
- Cfloat('3.14') == str('3.' + '14')
- D121 + 1 == int('1' + 2 * '2')
156Frage 116
What is the expected behavior of the following code?
class Class:
Var = 0
def __foo(self):
Class.Var += 1
return Class.Var
o = Class()
o.__Class_foo()
print(o.__Class_foo())- Ait raises an exception
- Bit outputs 3
- Cit outputs 1
- Dit outputs 6
157 Frage 117
What is the expected behavior of the following code?
x = 8 ** (1 / 3)
y = 2. if x < 2.3 else 3.
print(y)- Athe code is erroneous and it will not execute
- Bit outputs 2.0
- Cit outputs 2.5
- Dit outputs 3.0
158 Frage 118
What is the expected behavior of the following code?
my_list = [i for i in range(5, 0, -1)]
m = [my_list[i] for i in range(5) if my_list[i] % 2 == 0]
print(m)- Ait outputs [4, 2]
- Bit outputs [2, 4]
- Cit outputs [0, 1, 2, 3, 4]
- Dthe code is erroneous and it will not execute
159Frage 119
The __bases__ property contains:- Abase class location (addr)
- Bbase class objects (class)
- Cbase class names (str)
- Dbase class ids (int)
160 Frage 120
What is the expected behavior of the following code?
class Super:
def make(self):
pass
def doit(self):
return self.make()
class Sub_A(Super):
def make(self):
return 1
class Sub_B(Super):
pass
a = Sub_A()
b = Sub_B()
print(a.doit() + b.doit())- Ait outputs 0
- Bit raises an exception
- Cit outputs 1
- Dit outputs 2
Informationen
- Beschreibung
- Quiz am Python I, erstellt von Vit C am 09/09/2024.
- Autor
- Vit C
- Sprache
- English
- Aufrufe
- 193
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz