PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A program needs to read a user's age and print a message if they are 18 or older. Which code snippet correctly accomplishes this?
⚠ Common exam trap
Python Institute often tests the distinction between string and integer types, and the trap here is that candidates forget to convert the input to an integer, leading to a type mismatch error when using comparison operators like `>=`.
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: ')) if age >= 18: print('Adult')
It uses `int()` to convert the user input to an integer, then compares it with the integer `18` using the `>=` operator. This ensures a proper numeric comparison, and if the condition is true, it prints 'Adult'.
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 = int(input('Age: ')) if age >= '18': print('Adult')
Why it's wrong here
Compares int to string, raises TypeError.
- ✓
age = int(input('Age: ')) if age >= 18: print('Adult')
Why this is correct
Correct conversion and comparison.
- ✗
age = input('Age: ') if age >= 18: print('Adult')
Why it's wrong here
Compares string to int, raises TypeError.
- ✗
age = input('Age: ') if age == 18: print('Adult')
Why it's wrong here
Only checks exactly 18, not >=.
Go deeper
Related to this question
About these practice questions
One of 498 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 →
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.