Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A cashier script stores a product's unit price as a string read from a barcode label: price = '4.50'. The developer must compute the total for 3 units and print a numeric result. Which code produces the value 13.5?

⚠ Common exam trap

The trap here is assuming that any arithmetic on a numeric-looking string performs math, when Python instead repeats the string or raises an error depending on the operator.

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

✓

total = float(price) * 3

The price arrives as text, so it must be converted with float() before multiplication. float('4.50') becomes 4.5, and 4.5 * 3 evaluates to 13.5. Using int() fails on the decimal point, while string repetition produces concatenated text. The correct approach converts first, then computes.

Answer analysis

Option-by-option breakdown

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

  • ✓

    total = float(price) * 3

    Why this is correct

    float(price) parses the string '4.50' into the floating-point number 4.5, and multiplying by the integer 3 yields 13.5. This is the only option that both converts the text to a numeric type and performs arithmetic, so the printed value is the expected decimal total rather than a repeated string.

  • ✗

    total = price * 3

    Why it's wrong here

    Multiplying the string '4.50' by the integer 3 repeats the string three times, producing '4.504.504.50'. No numeric conversion occurs, so the calculation is meaningless for a price total. In Python, sequence repetition with an integer is legal for strings, which makes this mistake easy to overlook.

  • ✗

    total = str(price) * 3

    Why it's wrong here

    str(price) returns the same string '4.50', and multiplying it by 3 concatenates three copies. The result is text, not the numeric 13.5, and cannot be used in further arithmetic. Wrapping an already-string value in str() changes nothing about its type or behavior.

  • ✗

    total = int(price) * 3

    Why it's wrong here

    int('4.50') raises a ValueError because the string contains a decimal point, which int() cannot parse. The script terminates before any multiplication. Converting to int is appropriate only for whole-number strings such as '4' or '450', not for a decimal price read from a label.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

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.