PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A program calculates BMI. User inputs weight and height as strings. Which line correctly converts to float?
⚠ Common exam trap
Python Institute often tests the distinction between calling a function (`float(input())`) versus referencing it (`float(input)`) or chaining a non-existent method (`input().float()`), exploiting the common confusion that methods and functions are interchangeable.
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
✓
weight = float(input())
`float(input())` first reads the user's input as a string via `input()`, then converts that string to a floating-point number using the `float()` function. This is the standard Python pattern for converting user input to a numeric type.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
weight = float(input)
Why it's wrong here
float(input) passes the input function object itself to float, raising a TypeError rather than converting the entered string. It is tempting because it resembles the correct nesting order, and would work if input were replaced by a variable already holding the numeric string.
- ✗
weight = input().float()
Why it's wrong here
Strings have no float method, so input().float() raises an AttributeError. It is tempting because method-call syntax feels natural for conversion, and would be correct if the built-in float were instead a method defined on the string class.
- ✓
weight = float(input())
Why this is correct
float() parses a string such as "70.5" into a floating-point number, satisfying the stem's requirement to convert string input before arithmetic. Applying it directly to input() wraps the read value, so weight becomes numeric and BMI division works.
- ✗
weight = input(float())
Why it's wrong here
input(float()) calls float with no argument, raising a TypeError before input ever runs. It is tempting because it looks like conversion wrapped around input, and would work if float() received a numeric string argument inside the call.
Go deeper
Related to this question
About these practice questions
One of 482 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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which function is used to read user input as a string?
easy- A.read()
- B.scan()
- C.get()
- ✓ D.input()
Why D: The `input()` function is the correct answer because it is the built-in Python function specifically designed to read a line of text from the user via standard input (stdin). It always returns the input as a string, regardless of whether the user types digits or other characters, making it the standard tool for console input in Python.
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.