PCEP Computer Programming and Python Fundamentals Practice Question
A Python program prompts the user for their age and stores it in a variable. Which is the correct way to convert the input to an integer?
⚠ Common exam trap
The PCEP exam often tests the misconception that `input()` returns a numeric type, leading candidates to forget explicit type conversion and choose option C, which stores the input as a string and causes type-related errors in subsequent operations.
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
✓
age = int(input("Age: "))
The `input()` function in Python always returns a string, and to perform arithmetic operations or numeric comparisons, the string must be explicitly converted to an integer using the `int()` constructor. This is a fundamental requirement for type conversion in Python when handling user input.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
age = str(input("Age: "))
Why it's wrong here
Still a string.
- ✗
age = float(input("Age: "))
Why it's wrong here
Converts to float, not integer.
- ✗
age = input("Age: ")
Why it's wrong here
Returns a string, not integer.
- ✓
age = int(input("Age: "))
Why this is correct
Correct conversion.
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.