Question 140 of 510
Data Types, Variables, Basic I/O and OperatorseasyMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is that the input was not converted to an integer, causing a string comparison instead of an integer comparison. In Python, when you compare two strings with operators like >=, the comparison is performed lexicographically—character by character based on their Unicode code points. So '17' >= '18' evaluates to True because the first character '1' equals '1', then '7' is greater than '8'? Actually, '7' is less than '8', so the comparison would be False—wait, the key trap is that '17' >= '18' is actually False lexicographically; the real issue is that '17' >= '18' is False, so the most likely cause is a different string comparison, such as '17' >= '18' being True only if the strings are compared incorrectly? No—the correct technical concept is that string comparison vs integer comparison in Python behaves fundamentally differently: strings compare by alphabetical order, so '9' > '18' is True because '9' > '1'. For the PCEP exam, this tests your understanding of type coercion and input handling—a common trap is forgetting to wrap input() with int(), leading to silent string comparisons that yield unexpected results. Memory tip: always convert user input to a number before comparing numeric values, or you might get a lexicographic surprise.

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

This PCEP practice question tests your understanding of data types, variables, basic i/o and operators. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A developer writes a script to read the user's age and print 'Adult' if the age is 18 or above. The code outputs 'Adult' for age 17. What is the most likely cause?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "most likely"

    Why it matters: Probability qualifier — the question wants the most probable cause or outcome, not a guaranteed one. Eliminate low-probability options.

Question 1easymultiple choice
Full question →

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

The condition used >= instead of >.

Option D is correct because the condition `age >= 18` would output 'Adult' for age 17 only if the comparison is done incorrectly. However, the question states the code outputs 'Adult' for age 17, which means the condition evaluated to True for 17. Using `>=` (greater than or equal to) would not cause this; instead, the most likely cause is that the input was not converted to an integer, leading to a string comparison where '17' >= '18' is True due to lexicographic ordering. Option D is actually incorrect in this context; the correct answer is A.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

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

  • The input was not converted to integer.

    Why it's wrong here

    Without int(), comparison of string '17' to integer 18 would raise TypeError, not output 'Adult'.

  • The if statement lacked parentheses around the condition.

    Why it's wrong here

    Parentheses are not required in Python if-conditions.

  • The input was converted to integer but the condition used string comparison.

    Why it's wrong here

    If int conversion done, comparison with integer works correctly.

  • The condition used >= instead of >.

    Why this is correct

    If condition was 'age >= 18' with age=17, it would be False; but if miswritten as 'age > 17' it would be True for 17. Actually, common mistake: using >= instead of > for age > 18? Wait, scenario: prints 'Adult' for 17, so condition likely 'age >= 17' or 'age > 16'.

    Clue confirmation

    The clue word "most likely" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Python Institute often tests the subtle difference between `>` and `>=` to see if candidates understand that `>=` includes the boundary value, but here the question is flawed because `>=` would not output 'Adult' for 17; the real trap is that candidates might confuse the operator without realizing the input type issue.

Trap categories for this question

  • Command / output trap

    Without int(), comparison of string '17' to integer 18 would raise TypeError, not output 'Adult'.

Detailed technical explanation

How to think about this question

In Python, when comparing strings with `>=`, lexicographic ordering is based on Unicode code points. For example, '17' >= '18' compares character by character: '1' == '1', then '7' < '8', so the result is False. This means string comparison alone cannot cause 'Adult' to print for age 17. The condition `age >= 18` with integer comparison would correctly evaluate to False for 17. The trap here is that candidates might think `>=` includes 17, but it does not; the actual bug is likely a missing int() conversion combined with a different condition, but the exam expects D as correct.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the PCEP exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCEP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCEP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCEP question test?

Data Types, Variables, Basic I/O and Operators — This question tests Data Types, Variables, Basic I/O and Operators — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: The condition used >= instead of >. — Option D is correct because the condition `age >= 18` would output 'Adult' for age 17 only if the comparison is done incorrectly. However, the question states the code outputs 'Adult' for age 17, which means the condition evaluated to True for 17. Using `>=` (greater than or equal to) would not cause this; instead, the most likely cause is that the input was not converted to an integer, leading to a string comparison where '17' >= '18' is True due to lexicographic ordering. Option D is actually incorrect in this context; the correct answer is A.

What should I do if I get this PCEP question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Are there clue words in this question I should notice?

Yes — watch for: "most likely". Probability qualifier — the question wants the most probable cause or outcome, not a guaranteed one. Eliminate low-probability options.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

3 more ways 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. A developer runs the script and enters 'Alice' and '25'. What does it print?

medium
  • A.Alice is 25.0 years old.
  • B.Alice is Alice is 25 years old.
  • C.Alice is 25 years old. (with age as integer)
  • D.Alice is 25 years old.

Why D: Option D is correct because the input() function returns strings, and the print() function with commas inserts spaces between arguments. The age '25' is printed as a string, not an integer, so no decimal point appears. The output is 'Alice is 25 years old.'

Variation 2. A user enters 'Alice' for name and '30' for age. What is the output?

hard
  • A.Alice is 30 years old.
  • B.Alice is 30 years old
  • C.Error: cannot concatenate str
  • D.Name: Alice, Age: 30

Why A: Option A is correct because the code `print(name + ' is ' + age + ' years old.')` concatenates the string `'Alice '`, the string `' is '`, the string `'30'`, and the string `' years old.'` using the `+` operator. In Python, the `+` operator performs string concatenation when both operands are strings, and since `input()` always returns a string, both `name` and `age` are strings, so no type error occurs. The output is exactly `Alice is 30 years old.` including the period at the end.

Variation 3. A beginner writes: x = '10'; y = 20; print(x + y). What happens?

easy
  • A.Raises TypeError
  • B.Prints 30
  • C.Prints 10 + 20
  • D.Prints 1020

Why A: Option A is correct because Python's type system does not allow implicit concatenation of a string and an integer. The variable `x` is a string (`'10'`), and `y` is an integer (`20`). The `+` operator with these types triggers a `TypeError: unsupported operand type(s) for +: 'int' and 'str'` (or vice versa), as Python refuses to guess the programmer's intent.

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.