PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
What is the correct way to read a floating-point number from user input and store it in a variable?
⚠ Common exam trap
Test-takers frequently confuse the order of operations, thinking they can apply a type conversion method directly on the input string (like `.float()`) or use non-existent syntax like `as float`, instead of wrapping the `input()` call with the `float()` function.
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
✓
x = float(input())
`float(input())` first reads the user input as a string via `input()`, then converts that string to a floating-point number using the `float()` function. This is the standard and only valid way in Python to obtain a float from console input, as `input()` always returns a string.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
x = input(float())
Why it's wrong here
Invalid syntax; input() expects a string prompt.
- ✗
x = input() as float
Why it's wrong here
Invalid syntax.
- ✓
x = float(input())
Why this is correct
Reads input as string, then converts to float.
- ✗
x = input().float()
Why it's wrong here
Strings have no .float() method.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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 →
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.