Courseiva
Functions, Tuples, Dictionaries and ExceptionsmediumMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

Exhibit

def outer():
    x = 10
    def inner():
        nonlocal x
        x = 20
        print(x)
    inner()
    print(x)

outer()

Refer to the exhibit. What is the output?

⚠ Common exam trap

Many exam-takers confuse the unpacking of a tuple in a function call with printing the tuple directly, leading them to think the output is a single value or misorder the printed numbers.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

20 20

The exhibit shows a function `process` that takes a tuple `data` and converts it to a list, modifies the first element to 20, and returns a tuple of the first two elements. When called with `(10, 20, 30)`, the first call returns `(20, 20)`, so `print(process((10, 20, 30))[0])` prints `20`. The second call does the same, so `print(process((10, 20, 30))[1])` also prints `20`. Thus, the output is two lines each containing `20`.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 20 20

    Why this is correct

    Correct. Both prints show 20.

  • 10 20

    Why it's wrong here

    Incorrect. The order is first inner prints, then outer prints.

  • 10 10

    Why it's wrong here

    Incorrect. The variable is modified.

  • 20 10

    Why it's wrong here

    Incorrect. The nonlocal modification affects the outer variable.

About these practice questions

This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.