Description
Fix the Python script to print the flag. The script has a comparison error.
Setup
Download fixme2.py from the challenge page.
Solution
Want to try it yourself first?
The guided walkthrough reveals hints one step at a time.
Step 1Identify the bug
ObservationThe 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 = "":.pythonpython3 fixme2.pyExpected output
File "fixme2.py", line 7 if flag = "": ^ SyntaxError: invalid syntaxWhat 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 anifcondition is aSyntaxError- 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.Step 2Fix the comparison operator
ObservationThe 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.bashnano fixme2.pyWhat 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 equalis- identity check (same object in memory, not just equal value)is not- identity inequalityin- membership test
A subtle but important distinction:
==tests value equality whileistests object identity. For example, two separate empty lists[] == []isTrue, but[] is []isFalsebecause they are different objects. Useisonly when checking againstNone,True, orFalse.Step 3Run the fixed script
ObservationThe 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.pythonpython3 fixme2.pyLearn more
After correcting the operator, the
ifcondition 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.