1. Mixing Up = and == in Conditions
This one shows up in loads of beginner scripts.
If you write:
Python will throw a SyntaxError because you’re trying to assign inside the if.
Easy fix:
Use == inside if, elif and while:
Whenever you see a condition, quickly scan for = and ask yourself: “Am I comparing or assigning?”
2. Indentation Errors (Tabs vs Spaces)
Python is very picky about indentation. One extra space can break the whole script and give you:
IndentationError: unexpected indent
IndentationError: unindent does not match any outer indentation level
This usually happens when:
Easy fix:
Pick one style and stick to it. Most editors use 4 spaces per indent. Turn on “show whitespace” or similar in your editor so you can see tabs/spaces, and use the “convert indentation” or “re-indent” option if it exists.
Also, whenever you open a new block (after if, for, while, def, class), press Enter and then one indent level – not more, not less.
3. Treating User Input as a Number Without Converting It
input() always gives you a string, even if the user types 10. This leads to errors like:
You’ll get:
TypeError: `>` not supported between instances of `str` and `int`
Easy fix:
Convert the input to the correct type straight away:
Wrap it in try/except if your brief mentions validation:
4. Off-By-One Errors With range() and Indexes
You think your loop should run 10 times, but it only runs 9. Or you try to grab the last item and get:
IndexError: list index out of range
Common culprits:
-
Forgetting that range(0, 10) goes from 0 to 9.
-
Using the wrong index (e.g. my_list[len(my_list)] instead of len(my_list) - 1).
Easy fix:
Remember:
When you hit an IndexError, print the length and the index:
This makes it easier to see where you went “one too far”.
5. Using a Variable Before Defining It
You run your script and Python complains:
NameError: name `total` is not defined
This normally means:
-
You misspelled the variable name.
-
You are using a variable outside the block where it was created.
-
You defined it after you used it.
Easy fix:
Work top to bottom and make sure every variable is given a value before you use it. Also check spelling very carefully – total_price and total_prcie are not the same thing.
If you are using functions, pass values in and return values back instead of relying on random global variables.
6. Printing Instead of Returning in Functions
Many assignment briefs ask you to “write a function that returns X”. Students often write:
This will show a value on the screen, but it doesn’t return anything, so other parts of the programme can’t use the result.
Easy fix:
Use return when the marker expects a value, especially if the function will be tested in other code:
A good habit: print only in the main part of your script, and use return inside functions.
7. Type Errors From Mixing Strings and Numbers
Another classic:
You’ll get:
TypeError: can only concatenate str (not "int") to str
Easy fix:
Convert to string when you’re building messages:
or use f-strings (much cleaner):
Whenever you join things with +, check that both sides are the same type.
8. Import Problems and Missing Modules
Sometimes your script runs fine on your own laptop, but fails in the lab or on the marker’s system:
ModuleNotFoundError: No module named `pandas`
Or you accidentally name your file random.py and then:
starts importing your own file instead of Python’s built-in random module.
Easy fix:
-
Avoid calling your file the same name as a library (random.py, math.py, statistics.py, etc.).
-
If your assignment is allowed to use external libraries, note them clearly in the header comments and make sure they are installed (e.g. pip install pandas).
-
If the brief says “only use standard Python”, stick to built-in modules listed in the official Python library docs.
9. Ignoring Tracebacks and Guessing the Bug
Lots of students scroll past the red text and start guessing. The traceback is actually your best friend. It usually tells you:
-
The file and line number.
-
What went wrong (e.g. TypeError, ValueError, ZeroDivisionError).
-
The exact line that caused the crash.
If you ignore it, you can waste half an hour changing random lines.
Easy fix:
Read the traceback from the bottom upwards:
-
Look at the last line – that’s the real error type and message.
-
Look at the line of code it points to.
-
Print the values of the variables on that line to see what’s going on.
For example, if it says ZeroDivisionError on a line with x / y, print x and y one line earlier and check why y is zero.
10. Not Testing With “Ugly” Data
Your script works perfectly for the one nice example your tutor used in class… and then crashes on the real test data. That’s not always a Python error message – sometimes it’s a logic error which still ruins your marks because the output is wrong.
Examples:
-
You only test with positive numbers, but the marker uses zero or negatives.
-
You only test with short lists, but the marker uses an empty list.
-
You assume the user always types the correct thing.
Easy fix:
Before you submit, run your code with:
If your unit uses lab sheets or sample tests, go back and practise with those patterns again. It makes it easier to think like the person who will mark your work.
Final Tip: Get Another Pair of Eyes on Your Code
When you stare at the same error for too long, everything starts to look the same. A fresh pair of eyes – a classmate, a lab tutor, or a professional marker – can often spot the issue in minutes.
If you feel stuck, short on time, or worried about re-sits, you can also reach out for structured support. Our team offers dedicated python assignment help where real Python coders look at your brief, help you untangle errors, and guide you on how to present your scripts in a way markers actually like.
The more you understand these common mistakes, the less scary those red error messages become – and the more of your marks come from your ideas, not from fighting the interpreter.