r/learnpython • • 3d ago

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

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!

52 Upvotes

51 comments sorted by

3

u/Mundane_Emu_3 3d ago

Thank you so much everyone !

36

u/jbenze 3d ago

Start by writing the problem out on paper and walking through how you would solve it in pseudo code. Break it down into pieces, write it out and THEN translate it into code.

8

u/Warm_Letterhead3691 3d ago

100% this. Writing out the problem and your solution helps you find the ways your solution does and doesn't work. Plus it naturally gives your script structure when you go to build it. You'll end up breaking it up on paper into ways that work well when you translate them to functions and classes

3

u/Odd-Major-9038 3d ago

Can you guys give/show an example?

3

u/SharkSymphony 3d ago

Give us an example of something you want to do!

1

u/Odd-Major-9038 2d ago

I want to start writing the problem, I have done it through a process flow and that is easy, but the next step of taking it to code...just never can give 1 simple step

1

u/SharkSymphony 2d ago

You haven't given an example of something you want to do!

1

u/ComeSwirlWithMe 2d ago

I want to make claude and chatgpt robots and have them fight.

Gemini will be the referee.

5

u/jipperthewoodchipper 3d ago

Somewhere in one of the many boxes of stuff I have hoarded in my basement is a notebook filled with nothing but leet code problems that I solved on paper before trying to touch with code.

Back in the days when knowing how to solve tower of Hanoi was advantageous for technical interviews

3

u/jbenze 3d ago

I have stacks of yellow pads somewhere from interviews when you used to have to write code on paper.

2

u/Pyromancer777 2d ago

Mine is a google collab notebook I named "scratch paper" that is nothing but commented attempts at solving parts of a problem before trying to link everything together in the main Hackerrank interface (had a preference for Hackerrank over leetcode back in the day)

1

u/remic_0726 3d ago

Tu veux faire quelque chose, liste les mots du contexte, les noms,
les verbes, les propriétés, regroupe les en paquet cohérent, et tu vas obtenir des classes (noms), methodes (verbes), attributs (propriété). Et une classe est elle même découpée souvent en sous classe, donc réapplique la même méthode.

12

u/Both_Bend_2481 3d ago edited 3d ago

Every third beginner posts a similar question. You need to put in the work and practice. Code whatever programs you want.

edit: Just out of curiosity, what's something else you've done that you've become accomplished at, if anything? An art, or an instrument, or anything else that required practice and study? And how good have you become at it?

5

u/Pristine-Staff-5250 3d ago

Adding to this, code even the programs you don’t want

6

u/Financial_Farm4326 3d ago

pseudocode is huge for this tbh. write out every single step as a comment in your file first, then go back and fill in the actual python syntax underneath each comment so youre not fighting the logic and the language at the same time

1

u/Pyromancer777 2d ago

Instead of comments I use nested markdown checkboxes. The top box only gets a check if every nested step inside of it has been completed and those nested steps usually get broken down further into even more steps.

I also have a whiteboard that I use, but doesn't get updated nearly as often cuz I always have to erase stuff when I see checkboxes that haven't been broken into the most simple steps yet

5

u/ReddyKiloWit 3d ago

My first programming class - way too long ago - didn't have any code. We learned to break down problems and processes, write out the steps and draw diagrams of the logic needed. (I still have my logic symbol template.) It seems like a lot of people skip over that part and jump right to coding which is really secondary to developing a program. As others have suggested, pick a problem and then break it down into what steps are needed to get to a solution, and don't worry about syntax or even what language you'll use. Then practice that over and over.

1

u/thequestison 3d ago

Is it possible to get a copy of your logic symbol template?

2

u/ReddyKiloWit 2d ago

It's a piece of plastic for drawing flow chart symbols, can't really copy it. Search for: computer flow chart template. Pacific Arc makes a nice one.

You'll also need some instruction in flow charting if you've never done it. There are probably some tutorials online, and this book may be a good, cheap, start (Amazon has it for $3 in Kindle format.):

Pseudocode and Flowcharts Workshop for Beginners: Plan Programs Clearly Before Writing Code
by Corin Halstead 

It's recent, and I can't find any reviews, but the description is promising since it seems to address exactly the problem of the OP and others, i.e.: moving on to actually solving programming problems, and it's Python-related

4

u/Slothemo 3d ago

This is extremely common for beginners, and it mostly comes down to practice. The more problems you solve, the more patterns you will start to see emerge in how things are solved.

I really recommend a challenge site like Codewars and just work through as many problems as you can to build up the repetition. Once you feel a bit more confident, you can start working on your own mini-projects.

3

u/real_deal_engineer 3d ago

This isn’t a Python problem. Forget Python and solve the problems in natural language or on paper using regular symbols and math. Only then can you translate it to any language, not just Python.

3

u/peakpirate007 2d ago

been building https://www.runtime.school/ for learning and practicing python in one place. lessons, practice, projects and a few tools all use the same datasets, so it feels more connected than jumping between random examples. if you’re learning python , might be useful.

2

u/_b10ck_h3ad_ 3d ago

You basically have to develop your "thinking of real world problem in code based solution" brain, which comes with time & practice. It's highly recommended whenever learning a new programming language, to try & code up a simple game (e.g. tic tac toe) that incorporates the concepts you've learned so far.

2

u/t92k 2d ago

That’s what algorithms and design patterns teach you. There are very few completely unique problems in software, rather you want to know enough patterns to be able to move from hacky solutions up though serviceable, efficient, and elegant solutions.

2

u/BotSlamminDayNNight 2d ago

if you were to solve the/a problem without a computer, you could write the steps that another human could follow, i'm sure.
breaking things down for a computer requires a level of detail and accommodation that many are not prepared to engage.
it could be time for you to bust out some old school technology: try this book:
Computational Thinking: A beginner's guide to problem-solving and programming

1

u/Narrow_Ad_8997 3d ago

Puzzles... Advent of code starts tonight at midnight EST

1

u/Lyaw_Lyawa 3d ago

Diagramas de flujo. Es más fácil hacer algo con un paso a paso.

1

u/SharkSymphony 3d ago

What problem are you trying to solve?

1

u/SFJulie 3d ago

https://adventofcode.com/

With this yearly progessive challenge you can put in practice theoritical knowledge and hone your skills!

1

u/not_the_boulder 3d ago

My professor said that programming is like a sport, you have to practice.

Take some free online courses. Go through some books, and go through the exercises. Half of a university education is being exposed to a catalogue of problems.

1

u/BUYTBUYT BUYT-1 3d ago

Also a thing I've found that works: work through several examples yourself, manually, up to a point where you start to get a feel for it, then pay attention to what you're doing.

1

u/Fragrant-Cheek-4273 3d ago

I think you should stop relying on tutorials for now. Solve small problems on your own. My tip is to explain the logic in english before coding.

1

u/AlgoMonster_Official 2d ago

Try to keep simple rule, like no games for example, until you've done 30 min of programming, same time every day, helps more than waiting for passion to show up.
Use that time on something small you actually want, like a script for a game you play. You will see yourself improving over a few weeks.

1

u/4Floaters 2d ago

Sometimes it helps me to start at the end and work backwards

1

u/Awkward_Block9860 2d ago

The best I can do sometimes is to look at a solved problem similar to what I am trying to do and solve mine in a similar way.

1

u/LampstandTechKS 2d ago

Echoing a lot of others. I never sketched stuff out when I started. But I would always start with a single problem. I have A, I want to end up at Z, and B is the first obstacle in the way. I always found that if I had a concrete issue I was trying to solve for instead of coming up with some abstract concept, the problem itself usually ends up defining what options the solution should be.

Also, don’t get hung up on “is this the best way to do this?” at first. Starting out, the goal is small wins on concrete steps, knowing you’ll look at the code 6 months later and ask “what was I thinking?”

1

u/TheRNGuy 2d ago

Learn over long time. 

Your first code will be very bad.

Use frameworks, don't make worse versions of already existing functions and classes, save that time making the actual higher-level software.

Ask AI to review your code, hd can give good advices.

1

u/cmxthirtysixhundred 2d ago

That's when the fun begins, my friend!

When you get stuck, find a solution on stack overflow or something. Copy and paste it in to your stuff, but walk through it and learn what it does. Comment the code with what you understand it to be doing.

Next, if a stack overflow solution isn't quite perfect for your scenario, don't discard it. Copy and paste their code into yours, but modify it to fit your needs.

Understanding how other people solve problems was very helpful to me.

Also something I don't see emphasized enough: there is no one solution to a problem. People can critique all day about how they would have done something, but in code, if it works it works.

1

u/Pangaeax_ 1d ago

I think the problem is you're focusing more on learning syntax than actually solving problems. Try breaking each question into smaller steps and writing the logic in plain English before touching Python.

Start with easy challenges and gradually increase the difficulty. Platforms like Codewars and HackerRank are good for this. CompeteX by PangaeaX is also worth exploring if you want to apply Python through practical data challenges.

And don't look at solutions too quickly. Even if you can't solve something, spending 20-30 minutes figuring out the approach can teach you a lot more than watching another tutorial.

1

u/ANDRE_2512 22h ago

Learning programming languages with animated widgets in OpenGhost is a real pleasure.

1

u/mstrippolidev 8h ago

I will recommend do problem in leetcode, the easy ones, like 50 or 100 problems.

1

u/net_ramblings 3d ago

Klondike bar.

0

u/Serious_Hunt_763 3d ago

You do not understand Python concepts, you think you do, but you honestly do not. You need to use them in practice or teach them to understand them, until then you are about as dumb as is an apple red? yes? why? what about green apples? yellow apples? what actually is an apple?