fixme2.py Beginner picoMini 2022 Solution

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.

Solution

Want to try it yourself first?

The guided walkthrough reveals hints one step at a time.

Walk me through it
  1. Step 1
    Identify the bug
    Observation
    I noticed the challenge description mentioned a comparison error in the script, which suggested running it first to let Python's own error reporting pinpoint the exact line and operator causing the problem.
    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 = "":.
    python
    python3 fixme2.py

    Expected output

      File "fixme2.py", line 7
        if flag = "":
               ^
    SyntaxError: invalid syntax
    What didn't work first

    Tried: Run the script with python2 instead of python3 to see if it works without the error.

    Python 2 does allow assignment in some contexts but still raises SyntaxError for = inside an if condition - this is not a Python-version issue. The bug is a logical error (wrong operator) that must be fixed in the source file regardless of which interpreter you use.

    Tried: Comment out the if block entirely so the script skips the check and prints the flag unconditionally.

    The if block controls whether the flag is printed, so commenting it out may print nothing or cause an indentation error depending on what follows. The correct fix is to change = to == so the condition logic works as intended rather than bypassing it.

    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 2
    Fix the comparison operator
    Observation
    I noticed the SyntaxError pointed to an if condition using = (assignment) instead of a comparison operator, and looking at what the if block does (prints the flag) told me the condition needed != (not empty) so the block runs only when the flag is present.
    Open fixme2.py in nano. Change the single = to != on the flagged line. The corrected condition tests whether the flag string is not empty, so the block runs (and prints the flag) only when the flag has been loaded correctly.
    bash
    nano fixme2.py
    What didn't work first

    Tried: Use the is operator instead of == to fix the condition, writing: if flag is "":

    The is operator checks object identity (same object in memory), not value equality. In CPython some interned empty strings may pass, but this is an implementation detail and not reliable. The correct operator for comparing string values is ==, not is.

    Tried: Fix the condition by writing == so the script prints the flag when the variable is empty.

    The if block in this script prints the flag, so the condition should pass when the flag is present (not empty). Using == would mean the block only runs when the flag string is empty, which would never print a loaded flag. The correct operator here is !=.

    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 3
    Run the fixed script
    Observation
    I noticed the only reported error was the syntax mistake in the if condition, so once that single operator was corrected there were no remaining issues and re-running the script should print the flag.
    The script now runs without error and prints the flag.
    python
    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

Reveal flag

picoCTF{3qu4l1ty_n0t_4551gnm3nt_...}

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

Key takeaway

The assignment operator (=) and the equality test (==) are distinct in every C-family and Python language. Using = inside a condition is a SyntaxError in Python 3, but in C and C++ it silently compiles and always evaluates to the assigned value, which is a common source of logic bugs. Linters and compiler warnings (-Wall in GCC) catch this; the fix is always == for comparisons.

Related reading

Want more Beginner picoMini 2022 writeups?

Useful tools for General Skills

What to try next