r/CodingForBeginners • • 12h ago

I understand Python concepts, but I just can't seem to develop the logic to solve problems. How did you overcome this?

Hey everyone!

I've gone through multiple Python courses and understand the basic concepts like if-else, loops, lists, dictionaries, functions, etc.
However, when it comes to solving problems on my own, I struggle a lot. I can manage very basic questions like addition, subtraction, reversing a string, or checking for palindromes, but beyond that, I just can't seem to figure out the logic.
I understand the concepts and can follow someone else's solution, but when faced with a new problem, I have no idea where to start or how to break it down.
For those who have been through this, how did you develop your problem-solving skills? What kind of practice or approach helped you learn to think logically and solve problems independently?
I'd really appreciate any advice!

11 Upvotes

17 comments sorted by

6

u/TheUmgawa 12h ago

I took a community college class on programming ligic and design, where we never wrote a single line of executable code. It got me to unhook from the code and solve the problem by hand, often with the use of playing cards as data simulations. This was all done with flowcharts or incredibly terse pseudocode. My Yoda always said, “If you can solve it by hand, you can solve it in code.”

So, if something is complex enough that I can’t just hammer out the code in a couple of minutes, I still tend to scribble out a simplified flow diagram on a bar napkin, and then I’ve got a map. I can start by writing the code for the beginning, middle, or end, and it doesn’t matter, because it all gets integrated later.

2

u/No_Jaguar_5831 6h ago

Yep do what this guy says. Find a way to seperate from the syntax of code to solve your problem. Be it flow charts, diagrams, pseudocode, dice whatever. If you can write down your steps to solving the problem you'll learn to take a problem and turn it into smaller problems you can solve. Then you integrate them with each other. Divide and conquer is the method here.

1

u/dld2517 7h ago

I wish I could add a course like this to my program at community college. Sadly 45 hours fills up fast in today’s technology-filled world.

0

u/Unknowingly_know1 10h ago

I believe I saw your comment in another post a while ago, this is pretty interesting. Writing by hand helps a lot in memorising.

2

u/spacian 12h ago

It depends on what you mean with problem solving. For data structures and algorithms , I did a lot of l leetcode, reading and re-implementing solutions if I couldn't solve them, progressing from easy to hard. If you mean real world problems, there isn't much besides doing your own projects I think.

2

u/nacnud_uk 11h ago

Just walk it through as you would in real life. And then just translate that to computer steps. You know how to open a door, right? Really think about it, every step. Break it down as much as you want. Then re-work that into the computer language of your choice.

1

u/Square-Yam-3772 11h ago

you can just study the common approaches. There are popular/common ideas/strategies to solve problems to take advantage of Python's capabilities as a language.

recognize the patterns and apply the usual strategies.

I think it is a misconception that you have to "think like a computer". you really dont

not sure if you play chess but it is basically like chess: if you find yourself in certain situation, these are the moves and the ideas that other people usually try.

maybe this type of problem solving comes naturally to other people. if it doesn't come naturally to you, just study them.

1

u/Hkiggity 10h ago

What kind of problems? Like in projects you build? Or just random problems you find online

1

u/fltfathin 10h ago

Most problems are already solved and all you need is compose them, focus on input - > output, make procedures to fullfill the output from input, tadaa ur programmer

1

u/stepback269 10h ago

This is an often repeated question.
Here's the answer:

Code comes last.

That's right. You shouldn't try to solve the problem by immediately dumping some code onto your blank slate. There's a lot of "pre-production" thinking and planning that has to come first.

Imagine that you are thinking of producing a movie.
Let's say it's based on a novel that's already been written.

You can't just start filming.
Much planning has to go into the project well before you press the record button on your camera.

You have to "storyboard" the project first.
In what kinds of locations will the filming take place.
Which actors will be in each scene? How will they be positioned?
What support resources will you need?
What sequence of events is to take place at each scene?

IT'S THE SAME FOR PLANNING TO WRITE CODE !!!
What sequence of events is to take place at each phase of the program?
What support resources will you need?
Who are the actors? (Usually a human user --but not necessarily so)
... and so on

P.S. edit::: Here's a better search result: Storyboarding for Programmers

1

u/Remote-Dark-1704 8h ago

One caveat is that I think it’s perfectly fine to start with code, as long as you’re not trying to get the optimal solution, but rather just a solution that works.

A trivial, inefficient solution that works still teaches you a lot of stuff about the problem for you to think about when you plan how to actually solve it efficiently.

1

u/Reasonable_Slide6304 9h ago

start breaking the problem down to smaller and smaller pieces, what needs to be done to achieve the next thing etc.

are there conditions (if, else) do you need to repeat things and if so, is it a known amount (for) or does the repetition depend on the state of something (while)

do you repeatedly perform same set of actions on something (make it into a function)

are some set of data seeming to belong into a common group (class/struct)

do you have bunch of same things (arrays, lists)

the more you do things the easier it is to deconstruct the whole into smaller pieces and you can also try to train this for example taking some small simple game and writing down what is it made of. a while loop on the which the game logic runs until the game is closed and so on.

1

u/Recycled5000 8h ago

We need to repeatedly switch hats/ concerns.

One concern is what do we need to get done.

Another is how do we accomplish something we need.

Don’t let one bog you down. Keep thinking about them both.

They alternate. Something you can’t figure out how to do, break down the what some more until a how manifests.

1

u/Personal-March-4340 8h ago

My class used the textbook "Python for Everyone" by Horstmann, but any textbook will do. You start by writing the "Hello World" program and you work to a more complex structure.

The online tutorials I have seen teach you syntax, but you need to learn to figure out the logic by working on problems of increasing complexity.

You can stare at a pile of lumber and nails all day long, but that won't teach you how to build anything. You need to pick up a hammer and just start building. First a birdhouse, next a table, then a cabinet. Programming works the same way.

1

u/dld2517 7h ago

This problem has nothing to do with your programming skill and everything to do with how you break down a problem into smaller and more general steps. You should think about it like this: I have a limited inventory of ways to input, store, and access data. A) How do I get data into my program. B) How do I process the data / make decisions on it; C) how do I output it. Finally, If desired / necessary, D) How do I generalize the process to encompass more cases.

There are a lot of ways to solve problems not only one way. Often there is a best way but generally never an “only” way. As you become more comfortable with various data structures and procedures you will choose different ways to solve the problems.

1

u/LoudAd1396 7h ago

this is what you learn from experience. You solve a small problem, you solve a bigger problem, you solve a bigger-er problem...

There is no shortcut.

1

u/leogodin217 24m ago

A lot of good advice from others. I'll add that you should be building things, even small things. If you've taken several courses and you are trying to solve problems but never built anything, that is a huge red flag. You learn way more completing a project than taking more courses and doing Leet Code.

Of course, I'm making assumptions from your post. Disregard if I interpreted it wrong.