r/CodingForBeginners • u/Mundane_Emu_3 • 5d 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!
7
u/TheUmgawa 5d 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/spacian 5d 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 4d 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.
2
u/Hkiggity 4d ago
What kind of problems? Like in projects you build? Or just random problems you find online
1
u/Square-Yam-3772 4d 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/fltfathin 4d 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 4d 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/Reasonable_Slide6304 4d 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 4d 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 4d 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 4d 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 4d 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 4d 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.
1
u/korywithawhy 4d ago
so, one question you can ask yourself that may help is "what needs to be true to do the thing i want to do?" like if you want to write a program that blinks and led, you say okay for an led to blink, this device need to know there's an led there. how does it know that? how does it know to make it blink? how does it know to turn it on? how does it know to stop? then just start finding answers to those questions. eventually you get to a point where all the things that were blocking you are solved and you made an led blink. and the same approach can be used for most things. i am an industrial maintenance electrician by trade, a lot of my job is troubleshooting CNC equipment. asking those kinds of questions helps identify where the problem is likely to be.
1
u/DrBretto 4d ago
That is the point of the exercises, basically. Each time you struggle with that logic, you're forced to think about things in a way you haven't before, which builds your skill. So what you are experiencing is normal. Just keep on keeping on.
1
u/Maghioznic 4d ago
Then, for each smaller problem:
2a. Representation/Data Structures: Figure out how to represent the data of your problem.
2b. Processing/Algorithms: Figure out how to solve the problem; i.e. how to process your data to get the results you need.
1
u/Super_Math3890 3d ago
It's the same in art, music, or weightlifting. Practice, practice, and more practice.
1
u/Zalagal 3d ago
Nowadays I would tell you to ask ai the following question: " I have very basic knowledge on python. I want to implement <your exercise>. I understand I need to use <a python dict | two classes | a function that initialices a pet object with a random name > " (there you provide all the knowledge you have that you feel ilcould be useful) . And lastly you ask: " What do you think I should do first? Don't give me specific code, but a general solution that seems simple enough to start with."
I'm learning to build my own Quickshell widgets by using that kind of prompt and I am both learning, getting widgets projects done without spending too much time watching tutorials/reading docs.
At some point it would be a good idea for you to just read other peoples code. You can learn much more on software design by reading than by coding.
0
u/[deleted] 3d ago
Hey there, the practical bit to coding is based on principle. If you can add and subtract. Then you can learn rules. If you can learn rules then the code can slowly add or subtract. Keep it simple & document/share what you practise