fixme2.py

Published: April 2, 2026

Description

Fix the Python script to print the flag. The script has a comparison error.

Download fixme2.py from the challenge page.

Open it in a text editor.

Solution

  1. Step 1Identify the bug
    Run the script. Python 3 raises a SyntaxError because the condition uses = (assignment) instead of == (equality check). Find the line that reads something like: if flag = "":.
    python3 fixme2.py
    Learn more

    The assignment operator = stores a value into a variable. The equality operator == tests whether two values are equal and returns a boolean. Confusing the two is one of the most common beginner programming mistakes across all languages.

    In Python 3, using = inside an if condition is a SyntaxError -- the interpreter catches this at parse time before the script ever runs. This is a deliberate design choice: Python's grammar simply does not allow assignment in that position, preventing a whole class of silent bugs.

    By contrast, C and C++ do allow assignment inside conditionals -- if (x = 5) silently assigns 5 to x and evaluates as true, which is almost never what the programmer intended. This is why many C style guides recommend writing constants first: if (5 == x) so the compiler catches the mistake.

  2. Step 2Fix the comparison operator
    Change the single = to == on the flagged line. The corrected condition reads: if flag == "": -- this tests whether flag is empty rather than attempting to assign to it inside a conditional.
    Learn more

    Python offers several comparison operators beyond ==:

    • != -- not equal
    • is -- identity check (same object in memory, not just equal value)
    • is not -- identity inequality
    • in -- membership test

    A subtle but important distinction: == tests value equality while is tests object identity. For example, two separate empty lists [] == [] is True, but [] is [] is False because they are different objects. Use is only when checking against None, True, or False.

  3. Step 3Run the fixed script
    The script now runs without error and prints the flag.
    python3 fixme2.py
    Learn more

    After correcting the operator, the if condition properly tests whether the flag variable is an empty string. If it is not empty (meaning the flag has been loaded correctly), the script proceeds to print it.

    This pattern -- checking whether a variable is empty before using it -- is a common defensive programming technique. In real applications, it guards against uninitialized values or missing configuration causing crashes downstream. The bug here simulates a realistic mistake that even experienced developers occasionally make when typing quickly.

Flag

picoCTF{...}

= assigns a value; == tests equality. This is one of the most common beginner Python errors -- Python 3 raises a SyntaxError for = in conditions, unlike some languages that silently allow it.

More General Skills