It's completely normal for programmers to get stuck sometimes. It happens even to experienced developers, and quite frequently when doing unfamiliar things. Learning to persist and get unstuck is part of the programming skillset.
Below is a list of approaches and techniques. They are based on many years of experience developing software, and usually help beginners get unstuck.
Beginners get stuck for one of two reasons:
The first is a syntax problem. The second is a thinking problem.
Which of the two problems are you struggling with right now?
You're having syntax problems if you don't precisely what to type to make Python do as you want.
You can often use examples to figure out how to do something. You can:
If you've written code and are getting an error, read the error message closely several times. It can be hard to understand errors, but if you can understand the error you'll often get unstuck.
If you don't understand the error, you can:
When a software problem is easy and familiar, we can typically do it without much thought. When we run into a challenging problem, it's easy to default to the same approach. You end up just trying things, hoping that something will work.
But when that fails, we must step back and think. We must ensure that our mental model is clear before proceeding.
At risk of stating the obvious, if you're given an exercise and some words aren't clear, then review the terminology. It should be completely clear to you what you're trying to accomplish, even if you don't yet know how to get there.
If you're asked to write a function with inputs and outputs, it's often helpful to think of some concrete input and walk through what the output should be and why.
Write down in plain English what you want your program to do before you write any code. This forces you to develop a clear approach to the problem. It also prevents you from getting bogged down in the details of syntax. This approach is referred to as writing pseudocode first.
When you struggle with a problem, get stuck, and then spend some time doing other things, your brain continues to work on the problem in the background. This process is known as incubation in science. Research shows that sleep is particularly effective for incubation.
If you try returning to the problem the next day, you'll often be surprised to find that everything is much clearer.
Sometimes the problem seems clear in your head. But if you try explaining it to someone else, out loud, you'll see that your mental model was muddy all along. There is something about making your thoughts explicit and formal through language that often works to get programmers unstuck. This is known as rubber duck debugging.
So grab a friend, a pet, or a rubber duck, or hop on a chatroom. Explain the problem you're having out loud or in text. You may find it helps surprisingly much. For chat rooms you can join our Discord or try the /r/learnpython subreddit.
Try reading our post on how to approach a coding exercise. It gives a more structured approach that you'll probably find helpful for difficult exercises.