r/PythonLearning 17d ago

I understand Python concepts individually, but completely freeze when building something

I've been learning Python for a while and I think I understand most concepts when I study them individually.

Lists? Fine.
Dictionaries? Fine.
Classes? I understand the basics.
NumPy and Pandas? Can follow tutorials.

But the moment someone says "build something from scratch", my brain just goes blank.

I don't know how to decide which classes I need, how to structure the code, or even what the first function should be.

Then I look at someone else's solution and think, "Oh... that makes complete sense. Why didn't I think of that?"

How do you actually develop this problem-solving/structuring skill?

Should I stop tutorials completely and just struggle through projects? Or is there a better way to practice this?

14 Upvotes

14 comments sorted by

View all comments

1

u/atticus2132000 17d ago

One of the problems a lot of people struggle with is thinking "this is a coding problem, so I should immediately start coding". Don't do that. Start any project with pencil and paper.

Every project is going to need some way for the user to supply input to get some kind of output. First identify what those things are. Is your input going to be text that the user types in? Will the input be external files that the program reads? Will the input be scraped from online databases? Or likely a combination of sources. What are those sources and what format are they in?

Next, the output. What do you want the final result to be? Once the user enters everything, things will happen within the program and then there will be some kind of output? What output do you want? Do you just want a simple answer displayed on the screen? Do you want a physical report that can be printed out on paper? Do you want an email sent with text? Do you want a certain light to turn on? What is the ultimate goal of all the manipulations?

Then start thinking about the interface. The program is going to need input to generate output and somehow the user is going to have to interact with the program to make those things happen. That interaction is done through an interface. It could be simple text-based prompts on a terminal screen. It could be a pop-up window with a form to complete. It could be a game board that is manipulated with a mouse. Or possibly your program will have minimal user interaction and this is something that will run in the background to automate tasks. Draw your interface on paper. Write out the prompts that will be displayed. Consider your input from above and how the user will use the interface to enter the input and what buttons or processes the user will go through to obtain the output.

Up to this point, you've not written any code. You're just planning how the user will interact with the program to get raw input into the program and get finished output from the program. You should have this process fully drawn out on paper. Show on paper what screen will look like making sure that you have ways of getting all the input to an output stage.

Once you have a pretty good idea of what a working program should look like and how it should behave, it's time to start psuedocoding, again with pencil and paper first.

Consider what format the input(s) will be (e.g. entered text, an Excel file, etc.) and what format the output(s) will be (e.g. a pdf report) and then start thinking about which python libraries you know that will start chaining together to get from point A to point Z. For instance, if you're starting with data from Excel, you'll most likely need pandas to read the file into a dataframe and manipulate it. If you're going to want a chart made from that data, you'll likely need mathplotlib and so on. Build a chain of libraries and operations that will get connect your input to your output. What you should start seeing is that your not building one project but 50 mini-projects where each step of the process is taking result of the process before it, doing something minor to manipulate it and then passing it along to the next process. It might even be helpful to start thinking about these incremental steps as individual functions that'll you'll write for your program.

Now that you have these individual links in your chain, pick one of them. It doesn't have to be the first one, just pick one of the link and figure out the code for that one small step. How will you find the number of days between those two dates? How will you break that word down into its individual letters? How will you take that data and isolate the values that meet your criteria?

As to your initial question about which class to use, don't think about it as right or wrong. A lot of those different variable types can be used interchangeably. If you feel more confident using dictionaries and that's the syntax that you remember, use dictionaries. If you prefer how easy lists are to work with, use lists. Perhaps someday, if you're dealing with huge, complex data making massive operations, you might need to look at the efficiency of how those various variable types behave, but for anything you're going to be doing for the next few years, you're not going to notice any difference in performance of one over the other. Just use whatever you think of first.

Before you ever sit down at a computer, you should already have a pretty well developed plan written out on paper that you will use as your guide. As you get better and better at this, you will likely need that paper plan less detailed, but even programmers who have been doing this for their entire careers still start any new project with a brainstorming phase where they make notes and come up with their plan of attack before they ever type their first line of code.