Courseiva

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

A weather station records temperature as a string '23.5'. The technician writes code to convert to Fahrenheit for a report. Which code will produce the correct Fahrenheit value without errors?

⚠ Common exam trap

Python Institute often tests the distinction between `int()` and `float()` conversion, trapping candidates who forget that `int()` truncates the decimal part, leading to a loss of precision in calculations.

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

✓

fahrenheit = float(celsius) * 9/5 + 32

It explicitly converts the string '23.5' to a float using the `float()` function, preserving the decimal part. The expression `float(celsius) * 9/5 + 32` then correctly applies the Fahrenheit conversion formula (F = C * 9/5 + 32) using floating-point arithmetic, which yields the precise result 74.3 without any type errors.

Answer analysis

Option-by-option breakdown

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

  • ✓

    fahrenheit = float(celsius) * 9/5 + 32

    Why this is correct

    Converting the string with `float()` yields a numeric value, enabling the arithmetic `* 9/5 + 32` to compute Fahrenheit. This satisfies the stem's requirement to convert `'23.5'` without a `TypeError`, which string concatenation or integer parsing would cause.

  • ✗

    fahrenheit = celsius * 9/5 + 32

    Why it's wrong here

    Multiplying the string '23.5' by 9/5 raises a TypeError, since Python cannot perform arithmetic between str and float operands. It is tempting because this is the correct Fahrenheit formula once the value is numeric, and would work if the variable already held a float rather than a string.

  • ✗

    fahrenheit = int(celsius) * 9/5 + 32

    Why it's wrong here

    int() truncates if input has decimal, use float

  • ✗

    fahrenheit = (celsius + 32) * 9/5

    Why it's wrong here

    Wrong formula order

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.