Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A programmer is writing a Python script and needs to create variables that hold a user's name, age, and whether they are a student. Which TWO of the following assignments are syntactically valid and will execute without error in Python? (Choose two.)

⚠ Common exam trap

The trap here is focusing only on the value side of the assignment and overlooking identifier rules such as no leading digits, no hyphens, and no keywords.

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

✓

user_name = "Alice"

Valid Python identifiers must start with a letter or underscore, contain only letters, digits, and underscores, and must not be keywords. The assignments user_name = "Alice" and is_student = True satisfy these rules. Names starting with a digit, using hyphens, or using reserved words like class are invalid and cause syntax errors.

Answer analysis

Option-by-option breakdown

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

  • ✗

    class = "Math"

    Why it's wrong here

    class is a reserved keyword in Python used to define classes. Using it as a variable name causes a SyntaxError. Even though the assignment looks like a normal string assignment, the parser rejects any attempt to assign to a keyword.

  • ✓

    user_name = "Alice"

    Why this is correct

    This assignment uses a valid identifier: it starts with a letter, contains only letters and underscores, and is not a keyword. The string literal is properly quoted with double quotes. Python allows this and binds the string 'Alice' to the variable user_name without any syntax error.

  • ✗

    user-name = "Bob"

    Why it's wrong here

    The hyphen is not allowed in Python identifiers; it is interpreted as a minus operator. This line would be parsed as an expression involving subtraction, leading to a SyntaxError. Valid identifiers may contain letters, digits, and underscores only.

  • ✓

    is_student = True

    Why this is correct

    This is a valid assignment: is_student is a legal identifier (letters and underscore, no leading digit, not a keyword), and True is a built-in Boolean constant. Python executes this without error and binds the Boolean value True to the variable.

  • ✗

    2nd_age = 25

    Why it's wrong here

    An identifier cannot begin with a digit. Python raises a SyntaxError at parse time for names like 2nd_age. Although the rest of the name is valid, the leading digit makes this assignment invalid and the script will not run.

About these practice questions

One of 482 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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

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.