Visit Official SkillCertPro Website :-
For a full set of 755 questions. Go to
https://skillcertpro.com/product/python-pcap-31-03-exam-questions/
SkillCertPro offers detailed explanations to each question which helps to understand the concepts better.
It is recommended to score above 85% in SkillCertPro exams before attempting a real exam.
SkillCertPro updates exam questions every 2 weeks.
You will get life time access and life time free updates
SkillCertPro assures 100% pass guarantee in first attempt.
Question 1:
How many stars will the following code print to the monitor?
x = 1
while x < 5:
print(‘*‘)
x = x << 1
else:
print(2*‘*‘)
finally:
print(3*‘*‘)
A.Six
B. Five
C. The code is erroneous.
D. Three
Answer: C
Explanation:
Knowledge Area : Control Flow loops and conditional blocks
Topic : while-else loop, bitwise operator <<
More details:
The above code has a syntax error since finally: works with a try: block, not with a while-else loop.
If the 2 last lines of code were removed, then the result would have been five stars printed out on the screen : three stars from within the while loop and two from within the else: clause.
<< is a bitwise operator : x = x << 1 will double the value of x
Try it yourself:
x = 1
while x < 5:
print(‘*‘) # * -> * -> *
x = x < 4 -> 8
print(x)
else:
print(2*‘*‘) # **
#finally: # if uncommented : syntax error
# print(3*‘*‘)
Question 2:
What is the expected output of the following code ?
y = ‘R2D2‘
def my_func(x):
global y
y = x
return y
x = ‘Yoda‘
my_func(‘C3PO‘)
print(y)
A.Yoda
B.R2D2
C.C3PO
D.The code is erroneous.
Answer: C
Explanation:
Knowledge Area : Functions
Topic : global keyword
More details:
When you create a variable inside a function, that variable has a local scope, and can only be used inside that function.
With the global keyword, the scope of that variable will be extended to outside the function too.
The call to my_func(‘C3PO‘) will assign ‘C3PO‘ to the global variable y and print(y) will return C3PO.
Try it yourself:
y = ‘R2D2‘
def my_func(x):
global y
y = x
return y
x = ‘Yoda‘
my_func(‘C3PO‘)
print(y) # C3PO
Question 3:
Which statement about operators and their priorities is correct ?
A.Operator / has a higher priority than * .
B.Binary operators + and - have a lower priority than *.
C.Operator * has a higher priority than ** .
D.Unary operators + and - have a lower priority than **.
Answer: B and D
Explanation:
Knowledge Area : Basic Concepts
Topic : priority of operators
More details:
The priority of operators is as follow (by decreasing order of priority):
1 – ** (exponentiation)
2 – unary + and –
3 – *, /, and %
4 – binary + and -.
Try it yourself:
print(2**3*4) # 32
print(2*3+2*4) # 14
Question 4:
Which following statement is true (pick two) ?
A.Lambda is a correct variable name.
B.lambda is a correct variable name.
C.1lambda is a correct variable name.
D._lambda is a correct variable name.
Answer: A and D
Explanation:
Knowledge Area : Basic Concepts
Topic : variable name, Python reserved keywords
More details:
->“ lambda is a correct variable name.“ : this is false as lambda is a Python reserved keyword and cannot be used to name a variable.
->“ _lambda is a correct variable name.“ : this is true : a variable name can start with an underscore.
->“ 1lambda is a correct variable name.“ : this is false : a variable name cannot start with a number.
->“ Lambda is a correct variable name.“ : this is true. Lambda (note the upper-case “L“) is different from lambda (lower-case “l“) which is a Python reserved keyword.
Try it yourself:
#lambda = 5 # SyntaxError
#print(lambda)
_lambda = 4 # OK
print(_lambda) # 4
#1lambda = 3 # SyntaxError
#print(_lambda)
Lambda = 8 # OK
print(Lambda) # 8
Question 5:
What is the expected output of the following code snippet ?
i=0
while i in range(1,11,2):
print(i, end=‘‘)
else:
print(‘*‘)
A. 1357911*
B. 13579*
C. 13579
D. *
Answer: D
Explanation:
Knowledge Area : Control Flow loops and conditional blocks
Topic : while-else loop
More details:
With a while loop, the code within the loop will get repeated as long as the condition in the while statement is True.
Once the loop has exited, the else: branch gets executed (unless the while loop was terminated with a break statement).
Here variable i gets initialized with a value of 0, and 0 is not in range(1,11,2). So the code within the while branch does not get executed and the code within the else: branch is triggered : * is printed to the monitor.
Try it yourself:
i=0
while i in range(1,11,2): # 0 is not in range(1,11,2)
print(i, end=‘‘)
else:
print(‘*‘) # *
For a full set of 755 questions. Go to
https://skillcertpro.com/product/python-pcap-31-03-exam-questions/
SkillCertPro offers detailed explanations to each question which helps to understand the concepts better.
It is recommended to score above 85% in SkillCertPro exams before attempting a real exam.
SkillCertPro updates exam questions every 2 weeks.
You will get life time access and life time free updates
SkillCertPro assures 100% pass guarantee in first attempt.
Question 6:
What is the output of the following snippet of the user enters two lines containing 2 and 4 respectively ?
x = input()
y = int(input())
print(x * y)
A. 2222
B. 8
C. 2 * 4
D. The code is erroneous.
Answer: A
Explanation:
Knowledge Area : Data Types, Evaluations, and Basic I/O Operations
Topic : input() , * operator with one string , int()
More details:
The input() function always returns a string. So x is a string.
The int() function converts its argument (string, float, etc…) to an int. So, y is an int.
The * operator can be used with one string ABC and an int x : the result will be the string ABC repeated x times.
Try it yourself:
x = input(“Enter x:“) # enter 2
print(type(x)) #
y = int(input(“Enter y:“)) # enter 4
print(type(y)) #
print(x * y) # 2222
Question 7:
Consider the following code :
name=‘Han‘
def jedi(nm):
name=‘Luke‘
if nm==name:
return True
else:
return False
print(jedi(name))
What will be printed to the monitor ?
A. Luke
B. None
C. TRUE
D. False
Answer: D
Explanation:
Knowledge Area : Functions
Topic : function , scope of a variable
More details:
A variable that exists outside a function has a scope inside the function body unless the function defines a variable of the same name.
You can use the global keyword followed by a variable name to make the variable‘s scope global (i.e. the variable will have a scope inside and outside the function).
In the question above, the variable name=‘Han‘ has no scope inside the function since the function defines a variable with the same name (name=‘Luke‘ ).
So, in the last line of the code, the call to function jedi() is done with parameter name=‘Han‘ which returns False.
Try it yourself:
name=‘Han‘
def jedi(nm):
name=‘Luke‘
if nm==name:
return True
else:
return False
print(name) # Han
print(jedi(name)) # False
Question 8:
What is the expected output of the following code?
x = {(1, 2): 1, (2, 3): 2}
print(x[1, 2])
A. {(1, 2): 1, (2, 3): 2}
B. {1,2}
C. (1, 2), (2, 3)
D. 1
Answer: D
Explanation:
Knowledge Area : Data Collections Lists, Tuples, and Dictionaries
Topic : dictionaries, tuples
More details:
x is a dictionary and each of its key is defined as a tuple.
As a reminder, a tuple can be defined using parenthesis as in :
my_tuple = (1, 2, 4, 8)
but also without parenthesis, as in :
my_tuple = 1, 2, 4, 8.
x[1,2] is simply equivalent to x[(1,2)] which returns the corresponding value from the key (1,2) of the dictionary x, which is 1.
Try it yourself:
x = {(1, 2): 1, (2, 3): 2}
print(x[1, 2]) # 1
print(x[(1, 2)]) # 1
Question 9:
What is the output of the following snippet?
def myfun(n):
if n%2 == 0:
return 0
else:
return 1 + myfun(n+1)
print(myfun(5))
A. 1
B. 2
C. 7
Answer: A
Explanation:
Knowledge Area : Functions
Topic : function recursion
More details:
The above function uses recursion, which means the function calls itself.
To get the output of the function you simply have to go through each call of the function until a result is returned.
In the case of the above question, you start with n=5:
Since 5 is an odd number (5%2 returns 1), statement return 1 + myfun(n+1) gets executed.
To get the output of myfun(n+1), you need to go through the function logic again with n=6.
Since 6 is an even number (6%2 returns 0), statement return 0) gets executed.
So, now we can calculate the output of return 1 + myfun(n+1) when n was 5 : that‘s 1 + 0 , i.e. 1.
So, print(myfun(5)) will simply print 1 .
Try it yourself:
def myfun(n):
if n%2 == 0:
return 0
else:
return 1 + myfun(n+1)
print(myfun(5)) # 1
print(myfun(0)) # 0
print(myfun(1)) # 1
Question 10:
What is the expected behavior of the following snippet?
k = ‘Luke‘ # line 1
p = ‘Leia‘ # line 2
def x(k,p=‘-‘): # line 3
y = k[0] # line 4
return y # line 5
print(x(k)) # line 6
A. It will print L
B. The code is erroneous and will cause a runtime exception on line 4.
C. The code is erroneous and will cause a runtime exception on line 6.
D. It will print Luke
Answer: A
Explanation:
Knowledge Area : Functions
Topic : scope of a variable, functions : argument passing, default parameter values
More details:
The function x() takes two parameters : k and p ; those parameters have nothing to do with variables k=‘Luke‘ and p= ‘Leia‘. Parameter p is given a default value : ‘-‘ ; this means that if the function x() is called without argument p, its default value will be used instead (note that the function x() does not actually use this parameter anyway…).
So x(k) (where k= ‘Luke‘) is correct and it will return the first letter of the string ‘Luke‘ which is ‘L‘.
Try it yourself:
k = ‘Luke‘
p = ‘Leia‘
def x(k,p=‘-‘):
y = k[0]
return y
print(x(k)) # L
For a full set of 755 questions. Go to
https://skillcertpro.com/product/python-pcap-31-03-exam-questions/
SkillCertPro offers detailed explanations to each question which helps to understand the concepts better.
It is recommended to score above 85% in SkillCertPro exams before attempting a real exam.
SkillCertPro updates exam questions every 2 weeks.
You will get life time access and life time free updates
SkillCertPro assures 100% pass guarantee in first attempt.