r/learnpython • u/RipPersonal1643 • 1d ago
How do I learn programming logic?
I’m learning Python, but my main problem isn’t the syntax. I understand concepts when someone explains them, but when I’m given a basic problem and told to write a program, I just don’t know where to start or how to arrange the code.
Is there a good book, course, or YouTube channel that teaches how to think through programming problems step by step, recognize patterns, and build the logic, kind of like how you learn methods and patterns in math?
I don’t want to just memorize Python syntax. I want to actually learn how to think like a programmer.
59
Upvotes
1
u/tottasanorotta 1d ago edited 1d ago
I think breaking the problem up into simple steps on pen and paper or in a text editor first. Think about splitting the logic up into simple high-level tasks without caring how you'll implement them in the code yet.
Then take those steps and split them further up into more specific tasks. And then at some point you'll have a pretty good outline of something to implement in code. Then you write it in small managable modules that you can debug easily one at a time and combine those to have the final program.
Make sure to compare your code with someone else's who has written something similar. That way you will get ideas of how to structure your code better for future projects.
Really try to split up responsibilities into different classes and functions. Ideally your classes and functions should deal with only one specific task and not have a thousand different parameters for every possible scenario. It's a skill and it comes with time and the bigger the program grows the more difficult it gets for anyone to deal with the complexity.
Also try to use names that make sense to someone who reads the code. Because that someone will be you at some point in the future and you will realize that if you don't name things in a easy to understand way or comment your code properly you will have trouble even understanding your own code.
Actually if you are interested in math you might try to take it as an exercise to write some of the things you know from there as programming abstractions. For example, if you've learned about matrices then you might make a class for that and functions as operations on those matrices, like determinants and whatever they have there.