Courseiva

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

Which TWO of the following are valid ways to create a variable with the integer value 100?

⚠ Common exam trap

Python Institute often tests the distinction between numeric literals (like `100`), string literals (like `'100'`), and type conversion functions (like `int()`), and the trap here is that candidates may mistakenly think a string with digits is automatically an integer or that a float literal like `100.0` is equivalent to an integer.

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 = int('100')

Option C, x = int('100'), is correct because the int() constructor parses the string '100' and returns a genuine integer object with the value 100. Option D, x = 100, is correct because an unquoted numeric literal without a decimal point is directly an integer in Python, so x is bound to the int value 100. Option A, x = 0100, is not a valid way to get the integer 100 in Python 3, where a leading zero on a decimal literal is a syntax error (and in Python 2 it would denote octal 64, not 100). Option B, x = 100.0, creates a float, not an integer, even though its numeric value equals 100. Option E, x = '100', creates a string containing the characters 1, 0, 0, not an integer.

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 = 0100

    Why it's wrong here

    Python 3 rejects leading-zero decimal literals, so 0100 raises a SyntaxError; octal now requires 0o100. The leading zero tempts because Python 2 and C treat it as octal, but that syntax is invalid here, so no variable is created.

  • ✗

    x = 100.0

    Why it's wrong here

    100.0 is a float, not an integer, so it fails the requirement for an int value. It tempts because the numeric value equals 100, but the type differs; int(100.0) would satisfy the integer requirement, whereas the literal alone does not.

  • ✓

    x = int('100')

    Why this is correct

    Calling `int('100')` converts the string literal `'100'` into an integer object, which is then bound to the name `x`. This satisfies the stem's requirement for a variable holding the integer value 100, since `int()` parses the numeric characters and returns a genuine `int`, not a string.

  • ✓

    x = 100

    Why this is correct

    Assigning the literal 100 to the name x creates an integer variable directly, satisfying the stem's requirement for a valid variable creation with that value. Python infers the int type from the numeric literal, so no explicit declaration or constructor call is needed.

  • ✗

    x = '100'

    Why it's wrong here

    '100' is a string of characters, not an integer, so it fails the requirement. It tempts because the digits match the target value, but quoting makes the type str; int('100') would convert it, whereas the literal itself remains text.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.