Quiz
Python II
This quiz has a time limit, so it opens in the usual player.
Questions in this quiz (40)
1Frage 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
2Frage 2
Operator able to perform bitwise shifts is coded as (Choose two.)- A--
- B++
- C<<
- D>>
3Frage 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
4 Frage 4
The following expression
1+-2
is:- Aequal to 1
- Binvalid
- Cequal to 2
- Dequal to -1
5 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
6 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= '"')
7Frage 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
8 Frage 8
How many lines does the following snippet output?
for i in range(1, 3):
print("*", end="")
else:
print("*")- Athree
- Bone
- Ctwo
- Dfour
9Frage 9
Which of the following literals reflect the value given as 34.23? (Choose two.)- A.3423e2
- B3423e-2
- C.3423e-2
- D3423e2
10 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
11Frage 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]
12 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]
13Frage 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
14 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
15 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
16Frage 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
17Frage 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
18 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
19 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( )
20 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'}
21Frage 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
22Frage 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)
23Frage 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
24Frage 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]
25 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
26 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
27 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
28 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
29 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
30 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
31 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
32 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
33 Frage 33
The simplest possible class definition in Python can be expressed as:- Aclass X:
- Bclass X: pass
- Cclass X: return
- Dclass X: { }
34 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
35Frage 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
36 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")
37 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)
38Frage 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
39 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
40 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
Information
- Description
- Quiz on Python II, created by Vit C on 10/09/2024.
- Author
- Vit C
- Language
- English
- Views
- 0
- Rating
- No ratings yet Rate this quiz