Courseiva
Control Flow, Loops, Lists and LogichardMultiple ChoiceObjective-mapped

PCEP Control Flow, Loops, Lists and Logic Practice Question

A programmer has a list of tuples representing (product, price) and wants to find the highest price. Which code correctly finds the maximum price?

⚠ Common exam trap

Python Institute often tests the difference between `max()` returning the element that maximizes the key versus returning the key value itself, leading candidates to incorrectly choose option A when they want just the price.

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

max_price = max([price for product, price in prices])

Ly uses a list comprehension to extract all prices from the tuples, then passes that list to the built-in `max()` function, which returns the highest numeric value. This directly solves the problem of finding the maximum price without any unnecessary complexity.

Answer analysis

Option-by-option breakdown

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

  • max_price = max(prices, key=lambda x: x[1])

    Why it's wrong here

    Returns the entire tuple, not just the price.

  • max_price = max([price for product, price in prices])

    Why this is correct

    Correct; list comprehension extracts prices, then max finds the largest.

  • max_price = 0; for p in prices: if p[1] > max_price: max_price = p[1]

    Why it's wrong here

    Initializes to 0; fails if all prices are negative.

  • max_price = sorted(prices, key=lambda x: x[1])[-1]

    Why it's wrong here

    Returns the last tuple, not the price.

About these practice questions

One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.