Skip to main content

fixme2.py Beginner picoMini 2022 Solution

Correct a logic error in a Python script so it evaluates a condition properly and reveals the flag.

Published: April 2, 2026Updated: August 13, 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 1Identify the bug
    Observation
    The description mentions a comparison error in the script. Run it first and let Python's own error reporting pinpoint the line and the operator causing it.
    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 allows assignment in some contexts but still raises SyntaxError for = inside an if condition, so this is not a version problem. It is a logic error, the wrong operator, and it has to be fixed in the source whichever interpreter you use.

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

    The if block is what prints the flag, so commenting it out prints nothing, or triggers an indentation error depending on what follows. Change = to == so the condition 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 2Fix the comparison operator
    Observation
    The SyntaxError points at an if condition using = (assignment) instead of a comparison. Since the block prints the flag, the condition needs != so it runs only when the flag is actually 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 prints the flag, so the condition should pass when the flag is present, meaning not empty. Using == would run the block only when the flag string is empty, which never prints a loaded flag. The operator you want 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 3Run the fixed script
    Observation
    The syntax mistake in the if condition was the only error reported. With that one operator corrected there is nothing else outstanding, so 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.

Interactive tools
  • Strings ExtractorPull printable text from any binary, library, or image. ASCII and UTF-16 detection, configurable minimum length, flag-like highlight, no command line needed.
  • Regex TesterTest regular expressions against a string with live match highlighting, flag toggles, and common CTF pattern shortcuts.
  • Cyclic Pattern GeneratorGenerate de Bruijn cyclic patterns and find buffer overflow offsets. The browser equivalent of pwntools cyclic and cyclic_find.

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 Python and in every C-family language. Using = inside a condition is a SyntaxError in Python 3, but in C and C++ it compiles silently and evaluates to the assigned value, which is a classic source of logic bugs. Linters and compiler warnings such as GCC's -Wall catch it; the fix is always == for comparisons.

Related reading

Useful tools for General Skills

Where to go next