Quiz
Python PCAP Zertifizierung Quiz (241-280)
This quiz has a time limit, so it opens in the usual player.
Questions in this quiz (40)
1Aufgabe 1 (Buch 241)
What is the output of the following code?
def spam(x, sum):
return sum if x == 0 else sum + spam(x-1, sum)
print(spam(3, 0))- AA. SyntaxError: invalid syntax
- BB. 0
- CC. 6
- DD. RecursionError: maximum recursion depth exceeded in comparison
2Aufgabe 2 (Buch 242)
What do you call end in the print function call below?
print(x, end='')- AA. named argument
- BB. positional argument
- CC. keyword argument
- DD. arbitrary argument
3Aufgabe 3 (Buch 243)
How will you call the code below if you want to print 1, 2, 3?
def spam(a, b, c=3):
print(a, b, c)- AA. spam(1,2)
- BB. spam(1,2,3)
- CC. spam(b=2,a=1)
- DD. spam(a=1,2,c=3)
- EE. spam(a=1,2,3)
4Aufgabe 4 (Buch 244)
Which of the option(s) is valid based on the following code?
1 def spam(a, b, c=3):
2 print(a, b, c)
3 spam(1, 2, c=3,)- AA. a, b are positional arguments
- BB. 1, 2 are positional arguments
- CC. 1 2 3 will be printed
- DD. 3 is a positional argument
- EE. Invalid Syntax on Line 3
5Aufgabe 5 (Buch 245)
What is the output of the following code?
123
456
789- AA. No output
- BB. 123456789
- CC. SyntaxError: invalid syntax
- DD. NameError: name 123 is not defined
6>>> 2 ** 3 ** 2 #1 3**2=9
512
>>> 2 ** 9
512
What is the output of the following code?
>>> 2 ** 3 ** 2- AA. SyntaxError: invalid syntax
- BB. 12
- CC. 64
- DD. 128
- EE. 256
- FF. 512
7Aufgabe 7 (Buch 247)
What is the output of the following code?
>>> 5 ** 0 ** 0- AA. SyntaxError: invalid syntax
- BB. 1
- CC. 5
- DD. 0
8Aufgabe 8 (Buch 248)
i = 10
while len(str(i)) > 5:
i-=1
print(i, end='')
else:
i+=1
print(i, end='')- AA. 98765
- BB. 987656
- CC. 11
- DD. 11 .. 99999 will be printed
9Aufgabe 9 (Buch 249)
What is the output of the following code?
>>> i = 0
>>> while i != 0: i -= 1
... else: i += 1
>>> i- AA. SyntaxError: invalid syntax
- BB. 0
- CC. 1
- DD. 2
10Aufgabe 10 (Buch 250)
What is the output of the following code?
i = 30
while i > 0 :
i -= 10
print('loop', end=' ')
if i <= 10:
print('break', end=' ')
break
else:
print("else", end=' ')- AA. loop loop break
- BB. loop loop loop break
- CC. loop loop break else
- DD. loop loop loop break else
11Aufgabe 11 (Buch 251)
Which option(s) below will output
Hello World!
given the following code?
<<< INSERT CODE HERE >>>
print('World!')- AA. print('Hello')
- BB. print('Hello', ' ')
- CC. print('Hello', sep=' ')
- DD. print('Hello', end=' ')
12Aufgabe 12 (Buch 252)
Which option(s) will result in the output
0 1 2
Given the following code
c, b, a = 2, 1, 0
a, c = c, b
b = b - c
<<< INSERT CODE HERE >>>
print(a, b, c)- AA. a, b, c = b, c, a
- BB. c, b, a = a, c, b
- CC. b, c, a = a, b, c
- DD. a, c, b = c, b, a
13Aufgabe 13 (Buch 253)
What is the output of the following code?
def upcase(text):
return text.upper()
x = upcase
f = [str.lower, x, str.capitalize]
def dofunc(f):
message = f('Hello')
print(message)
dofunc(x)- AA. SyntaxError: invalid syntax
- BB. Hello
- CC. hello
- DD. HELLO
- EE. AttributeError: type object 'str' has no attribute 'capitalize'
14Aufgabe 14 (Buch 254)
Which option prints HELLO WORLD given the following code?
>>> def dofunc(text, b):
... def lowcase(): return text.lower()
... def upcase(): return text.upper()
... return upcase if b else lowcase- AA. >>> dofunc('Hello World', True)
- BB. >>> dofunc('Hello World', True)()
- CC. >>> dofunc('Hello World', (True))()
- DD. >>> dofunc('Hello World', (False,))()
15Aufgabe 15 (Buch 255)
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- AA. 1
- BB. 0
- CC. 2
- DD. the variable becomes unavailable
16Aufgabe 16 (Buch 256)
Operator able to perform bitwise shifts is coded as (Choose two.)- AA. --
- BB. ++
- CC. <<
- DD. >>
17Aufgabe 17 (Buch 257)
What will the value of the i variable be when the following loop finishes its execution?
for i in range(10):
pass- AA. 10
- BB. the variable becomes unavailable
- CC. 11
- DD. 9
18Aufgabe 18 (Buch 258)
The following expression -
1+-2
is:- AA. equal to 1
- BB. invalid
- CC. equal to 2
- DD. equal to -1
19Aufgabe 19 (Buch 259)
A compiler is a program designed to (Choose two.)- AA. rearrange the source code to make it clearer
- BB. check the source code in order to see of it's correct
- CC. execute the source code
- DD. translate the source code into machine code
20Aufgabe 20 (Buch 260)
What is the output of the following piece of code?
a = 'ant'
b = "bat"
c = 'camel'
print(a, b, c, sep='"') # '+"+ '- AA. ant'bat'camel
- BB. ant"bat"camel
- CC. antbatcamel
- DD. print(a, b, c, sep= '"')
21Aufgabe 21 (Buch 261)
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)- AA. the code is erroneous
- BB. 3
- CC. 7
- DD. 15
22Aufgabe 22 (Buch 262)
How many lines does the following snippet output?
for i in range(1, 3):
print("*", end="")
else:
print("*")- AA. three
- BB. one
- CC. two
- DD. four
23Aufgabe 23 (Buch 263)
Which of the following literals reflect the value given as 34.23? (Choose two.)- AA. .3423e2
- BB. 3423e-2
- CC. .3423e-2
- DD. 3423e2
24Aufgabe 24 (Buch 264)
What is the expected output of the following snippet?
a = 2
if a > 0:
a += 1
else:
a -= 1
print(a)- AA. 3
- BB. 1
- CC. 2
- DD. the code is erroneous
25Aufgabe 25 (Buch 265)
a = [1]
b = a
a[0] = 0- AA. len(a) == len(b)
- BB. b[0] +1 == a[0]
- CC. a[0] == b[0]
- DD. a[0] + 1 == b[0]
26Aufgabe 26 (Buch 266)
Assuming that the following snippet has been successfully executed, which of the equations are False?
(Choose two.)
a = [0]
b = a[:]
a[0] = 1- AA. len(a) == len(b)
- BB. a[0] - 1 == b[0]
- CC. a[0] == b[0]
- DD. b[0] - 1 == a[0]
27Aufgabe 27 (Buch 267)
Which of the following statements are true? (Choose two.)- AA. Python strings are actually lists
- BB. Python strings can be concatenated
- CC. Python strings can be sliced like lists
- DD. Python strings are mutable
28Aufgabe 28 (Buch 268)
Which of the following sentences are true? (Choose two.)- AA. Lists may not be stored inside tuples
- BB. Tuples may be stored inside lists
- CC. Tuples may not be stored inside tuples
- DD. Lists may be stored inside lists
29Aufgabe 29 (Buch 269)
Assuming that String is six or more letters long, the following slice
string[1:-2]
is shorter than the original string by:- AA. four chars
- BB. three chars
- CC. one char
- DD. two chars
30Aufgabe 30 (Buch 270)
What is the expected output of the following snippet?
lst = [1, 2, 3, 4]
lst = lst[-3:-2]
lst = lst[-1]
print(lst)- AA. 1
- BB. 4
- CC. 2
- DD. 3
31Aufgabe 31 (Buch 271)
What is the expected output of the following snippet?
s = 'abc'
for i in len(s):
s[i] = s[i].upper()
print(s)- AA. abc
- BB. The code will cause a runtime exception
- CC. ABC
- DD. 123
32Aufgabe 32 (Buch 272)
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]- AA. zero
- BB. five
- CC. seven
- DD. three
33Aufgabe 33 (Buch 273)
What would you used instead of XXX if you want to check weather a certain 'key' exists in a dictionary
called dict? (Choose two.)
if XXX:
print("Key exists")- AA. 'key' in dict
- BB. dict['key'] != None
- CC. dict.exists('key')
- DD. 'key' in dict.keys( )
34Aufgabe 34 (Buch 274)
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)- AA. dir={'Mom': 5551234567, 'Dad': 5557654321}
- BB. dir= {'Mom': '5551234567', 'Dad': '5557654321'}
- CC. dir= {Mom: 5551234567, Dad: 5557654321}
- DD. dir= {Mom: '5551234567', Dad: '5557654321'}
35Aufgabe 35 (Buch 275)
Can a module run like regular code?- AA. yes, and it can differentiate its behavior between the regular launch and import
- BB. it depends on the Python version
- CC. yes, but in cannot differentiate its behavior between the regular launch and import
- DD. no, it is not possible; a module can be imported, not run
36Aufgabe 36 (Buch 276)
Select the valid fun () invocations:
(Choose two.)
def fun(a, b=0):
return a * b- AA. fun(b=1)
- BB. fun(a=0)
- CC. fun(b=1, 0)
- DD. fun(1)
37Aufgabe 37 (Buch 277)
A file name like this one below says that:
(Choose three.)
services.cpython-36.pyc- AA. the interpreter used to generate the file is version 3.6
- BB. it has been produced by CPython
- CC. it is the 36 version of the file
- DD. the file comes from the services.py source file
38Aufgabe 38 (Buch 278)
What is the expected behavior of the following snippet?
def a(x, y):
return x[y]
print(a(0, [1]))- AA. cause a runtime exception
- BB. print 1
- CC. print 0,[1]
- DD. print [1]
39Aufgabe 39 (Buch 279)
What can you do if you don't like a long package path like this one?
import alpha.beta.gamma.delta.epsilon.zeta- AA. you can make an alias for the name using the alias keyword
- BB. nothing, you need to come to terms with it
- CC. you can shorten it to alpha . zeta and Python will find the proper connection
- DD. you can make an alias for the name using the as keyword
40Aufgabe 40 (Buch 280)
What is the expected output of the following code?
str = 'abcdef'
def fun(s):
del s[2]
return s
print(fun(str))- AA. abcef
- BB. The program will cause a runtime exception/error
- CC. acdef
- DD. abdef
Information
- Description
- Quiz on Python PCAP Zertifizierung Quiz (241-280), created by Marko Luzanin on 11/09/2024.
- Author
- Marko Luzanin
- Language
- Deutsch
- Views
- 6
- Rating
- No ratings yet Rate this quiz