100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 320
During a review of yield inside for loop, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def g():
for x in (2,4): yield x+1
print(list(g()))
Program B:
def g():
for x in range(1,4): yield x
it=g()
print(next(it),next(it))
Program C:
def g():
for c in "ab": yield c.upper()
print("".join(g()))
- Program B prints '120'.
- Program C prints 'ab'.
- Program B prints '1 2'.
- Program C prints '27'.
- Program A prints 'lookup'.
Explanation
Correct Answers
B:Running Program C prints 'ab'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
C:Running Program B prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Incorrect Answers
A:Program B does not produce '120'; its verified result is: Prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
D:Program C does not produce '27'; its verified result is: Prints 'AB'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
E:Program A does not produce 'lookup'; its verified result is: Prints '[3, 5]'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Question 321
A learner is checking positional argument binding. What is the exact printed result or uncaught exception?def sub(a,b): return a-b
print(sub(10,3))
- Prints '7'
- Prints '8'
- Prints '9'
- Prints '6'
Explanation
Correct Answer
A:The snippet prints '7'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Incorrect Answers
B:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '7'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
C:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '7'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
D:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '7'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Question 322
A developer tests positional argument binding. The following code prints '27'. Which explanation best accounts for that observed behavior?def f(x,y): return x*10+y
print(f(2,7))
- The except clause matching the raised exception class handles the error and allows execution to continue.
- KeyboardInterrupt and SystemExit derive from BaseException but not from the Exception subclass.
- A generator yields values lazily and resumes after each yield when next is called.
- Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints '27'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The exact exception handler selection topic does not explain why the code prints '27'. The relevant Python rule is: Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
B:The BaseException versus Exception topic does not explain why the code prints '27'. The relevant Python rule is: Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
C:The generator yield suspends state topic does not explain why the code prints '27'. The relevant Python rule is: Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Question 323
A learner is checking positional argument binding. After this modification, what does Python 3 actually do?def div(x,y): return x//y
print(div(9,2))
- Prints '4'
- Prints '3'
- Prints '5'
- Prints '6'
Explanation
Correct Answer
A:The snippet prints '4'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Incorrect Answers
B:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '4'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
C:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '4'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
D:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '4'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Question 324
During a review of positional argument binding, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def f(x,y): return x*10+y
print(f(2,7))
Program B:
def div(x,y): return x//y
print(div(9,2))
Program C:
def join(a,b): return a+":"+b
print(join("left","right"))
- Program B prints '4'.
- Program C prints "['a', 'b']".
- Program B prints '6'.
- Program A prints '16'.
- Program C prints 'left:right'.
Explanation
Correct Answers
A:Running Program B prints '4'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
E:Running Program C prints 'left:right'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Incorrect Answers
B:Program C does not produce "['a', 'b']"; its verified result is: Prints 'left:right'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
C:Program B does not produce '6'; its verified result is: Prints '4'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
D:Program A does not produce '16'; its verified result is: Prints '27'. Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Question 325
A learner is checking keyword argument binding. What is the exact printed result or uncaught exception?def sub(a,b): return a-b
print(sub(b=3,a=10))
- Prints '8'
- Prints '7'
- Prints '9'
- Prints '6'
Explanation
Correct Answer
B:The snippet prints '7'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Incorrect Answers
A:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '7'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
C:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '7'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
D:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '7'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Question 326
A developer tests keyword argument binding. The following code prints '24'. Which explanation best accounts for that observed behavior?def f(x,y): return x*10+y
print(f(y=4,x=2))
- A Python function without a reachable return statement returns the singleton None.
- Keyword arguments bind by parameter name regardless of the order in which keywords are written.
- Assigning to a parameter or local variable does not rebind the distinct global name without global.
- Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '24'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The implicit None return topic does not explain why the code prints '24'. The relevant Python rule is: Keyword arguments bind by parameter name regardless of the order in which keywords are written.
C:The local name shadows global name topic does not explain why the code prints '24'. The relevant Python rule is: Keyword arguments bind by parameter name regardless of the order in which keywords are written.
D:The positional argument binding topic does not explain why the code prints '24'. The relevant Python rule is: Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Question 327
A learner is checking keyword argument binding. After this modification, what does Python 3 actually do?def join(a,b): return a+"/"+b
print(join(b="end",a="start"))
- Prints 'dne/trats'
- Prints 'start/end'
- Prints 'start/end?'
- Prints 'start/en'
Explanation
Correct Answer
B:The snippet prints 'start/end'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Incorrect Answers
A:This predicts that the snippet prints 'dne/trats', but executing the displayed Python 3 code prints 'start/end'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
C:This predicts that the snippet prints 'start/end?', but executing the displayed Python 3 code prints 'start/end'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
D:This predicts that the snippet prints 'start/en', but executing the displayed Python 3 code prints 'start/end'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Question 328
During a review of keyword argument binding, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def f(x,y): return x*10+y
print(f(y=4,x=2))
Program B:
def join(a,b): return a+"/"+b
print(join(b="end",a="start"))
Program C:
def area(w,h): return w*h
print(area(h=3,w=7))
- Program A prints '12'.
- Program B prints '[0, 1, 4]'.
- Program C prints '[]'.
- Program C prints '21'.
- Program B prints 'start/end'.
Explanation
Correct Answers
D:Running Program C prints '21'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
E:Running Program B prints 'start/end'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Incorrect Answers
A:Program A does not produce '12'; its verified result is: Prints '24'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
B:Program B does not produce '[0, 1, 4]'; its verified result is: Prints 'start/end'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
C:Program C does not produce '[]'; its verified result is: Prints '21'. Keyword arguments bind by parameter name regardless of the order in which keywords are written.
Question 329
A learner is checking mixed positional and keyword calls. What is the exact printed result or uncaught exception?def f(a,b,c): return a+b+c
print(f(1,c=3,b=2))
- Prints '5'
- Prints '7'
- Prints '6'
- Prints '8'
Explanation
Correct Answer
C:The snippet prints '6'. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Incorrect Answers
A:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '6'. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
B:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '6'. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
D:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '6'. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Question 330
A developer tests mixed positional and keyword calls. The following code prints '123'. Which explanation best accounts for that observed behavior?def f(a,b,c): return 100*a+10*b+c
print(f(1,2,c=3))
- An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
- A global declaration makes assignment inside the function modify the module-level name.
- An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
- Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints '123'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The IndexError and KeyError distinct topic does not explain why the code prints '123'. The relevant Python rule is: Positional arguments may precede named arguments, but a single parameter cannot receive two values.
B:The global declaration changes module binding topic does not explain why the code prints '123'. The relevant Python rule is: Positional arguments may precede named arguments, but a single parameter cannot receive two values.
C:The nested try except responsibility topic does not explain why the code prints '123'. The relevant Python rule is: Positional arguments may precede named arguments, but a single parameter cannot receive two values.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests