Courseiva
Computer Programming and Python FundamentalsmediumMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

Exhibit

def calculate_discount(price, discount):
    if discount > 0.5:
        print("Discount too high")
        return price
    return price * (1 - discount)

Refer to the exhibit. What is the output when the following code is executed: print(calculate_discount(100, 0.6))

⚠ Common exam trap

The PCEP exam often tests the distinction between a function's printed output and its return value, leading candidates to overlook that both the print inside the function and the print of the return value appear in the output.

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

Discount too high followed by 100

The code defines a function `calculate_discount(price, discount)` that first checks if the discount is 0.6 or higher. Since 0.6 is exactly equal to 0.6, the condition `if discount >= 0.6` is true, so it prints 'Discount too high' and then returns the original price (100). The `print()` statement outside the function outputs the return value, which is 100, resulting in the output 'Discount too high' followed by '100' on the next line.

Answer analysis

Option-by-option breakdown

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

  • Discount too high

    Why it's wrong here

    The function also returns and prints the price.

  • 40.0

    Why it's wrong here

    40.0 is the discounted price for valid discount ≤0.5.

  • 100

    Why it's wrong here

    The message is also printed.

  • Discount too high followed by 100

    Why this is correct

    The print statement outputs the message, then the function returns 100 which is printed.

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.