Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A developer writes the following code and runs it without any error:

x = 5 y = 2.0 z = x + y

What is the value and type of z?

⚠ Common exam trap

The trap here is assuming the result keeps the integer type because the value looks whole, overlooking Python's automatic float promotion in mixed arithmetic.

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

✓

7.0, of type float

When Python evaluates an arithmetic expression containing both an int and a float, it converts the integer to a float and produces a float result. Adding five and two point zero yields the float value seven point zero. The variable z therefore references a float object, which can be verified by examining type(z) in the interpreter.

Answer analysis

Option-by-option breakdown

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

  • ✗

    A TypeError is raised because int and float cannot be added

    Why it's wrong here

    Python permits arithmetic between integers and floats without any explicit conversion. The interpreter widens the integer to a float and completes the addition normally. A TypeError would occur only with incompatible types such as adding an integer to a string without conversion, so this option does not describe the actual behavior.

  • ✗

    7, of type int

    Why it's wrong here

    Python does not truncate the float operand to keep an integer type. When an integer and a float are combined with addition, the integer is converted to a float first, so the result is a float. The value is numerically seven, but the type is float, not int, which makes this option incorrect.

  • ✓

    7.0, of type float

    Why this is correct

    Python's arithmetic follows a numeric type hierarchy, and mixing an int with a float promotes the int to float before the operation. The addition of 5 and 2.0 therefore produces 7.0 as a float object. The type of the variable z is float, confirmed by calling type(z), which returns the float class.

  • ✗

    7.0, of type str

    Why it's wrong here

    The plus operator between two numbers performs arithmetic addition, not string concatenation, because neither operand is a string. The result is a numeric float object, not text. Python would only produce a string if one operand were a string, and that would actually raise a TypeError here, so this option is incorrect.

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.