Follow these steps:
-
Don't Panic! Relax and realize that you will solve this problem, even if it takes a little bit of messing around. Banging your head against the computer is part of your job (both as a student and as a professional programmer). Remember that the computer is doing precisely what you are telling it to do. There is no magic.
-
Determine precisely what is going on. Did you get an error message from Python? If it is a
SyntaxError
, a helpful guide is here. Also, running your code in Python 3.11 or higher has improved error messages. -
Python error messages include a stack trace. There could be a number errors throughout the stack. You read a stack trace from bottom to top. Go slowly and understand each character and each line.
Given this Traceback:
"abc".uppre() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-2-a2268f9e2941> in <module> ----> 1 "abc".uppre() AttributeError: 'str' object has no attribute 'uppre'
I misspelled
upper()
asuppre()
. -
If it does not look like it is some simple mistyping, you might get lucky and find something in Google if you copy and paste the error message.
-
If your code is running without errors, then insert print statements to figure out what the variables are at different points. That often tells you what the problem is. Something like this often works:
print(f"Expected {foo}. But actually got {bar}.")
-
You get the most learning by trying to solve the problem completely on your own but don't waste too much time (~15 minutes at the upper end). You should seek external help. Options include ChatGPT, Stack Overflow, a peer, a senior team member, or an instructor.