Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

What is the output of the following code?

def greet(name, greeting='Hello'):
    print(greeting, name)

greet('Alice')

⚠ Common exam trap

Python Institute often tests whether candidates understand that default parameters are used when the corresponding argument is omitted, leading to the misconception that only the default value is printed or that a syntax error occurs.

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

✓

Hello Alice

The function `greet` has a default parameter `greeting='Hello'`. When called with only one argument (`'Alice'`), the default value is used for `greeting`, so the output is `Hello Alice`. The `print` function outputs both arguments separated by a space.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Hello

    Why it's wrong here

    The function prints both arguments, so the output is 'Hello Alice', not 'Hello'. The default greeting is supplied, but name is still printed alongside it. It tempts because 'Hello' is the default value, yet print receives two arguments and outputs both.

  • ✓

    Hello Alice

    Why this is correct

    Default parameters apply when an argument is omitted at call time. Calling `greet('Alice')` supplies only `name`, so Python binds `greeting` to its default value `'Hello'`, printing `Hello Alice`. The single positional argument satisfies `name`, leaving the optional parameter untouched.

  • ✗

    SyntaxError

    Why it's wrong here

    The call is valid: name is positional and greeting uses its default, so no SyntaxError occurs. It tempts because default parameters can cause ordering errors, but here the required argument precedes the default, so Python accepts it and prints 'Hello Alice'.

  • ✗

    Alice

    Why it's wrong here

    The function prints greeting then name, producing 'Hello Alice', not 'Alice'. Both parameters are printed, so omitting greeting from the output is wrong. It tempts because 'Alice' is the passed argument, but print outputs the greeting too.

About these practice questions

This PCEP question is part of Courseiva's 482-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.