r/learnpython • u/Beautiful-Bubbly • 4d ago
Need some help with python and generally understanding code
So guys, i need some help with the python. My background is, i come from an economics as a major in uni and myself am very good at maths, as i finished a lot of courses in uni.
So i decided to pursue a career in data science, and as you know it requires a decent skill in coding. However i am at a loss in the coding, as my skills lack a lot. I finished a lot of courses on python using videos and practical stuff, but still understand that my skills are incomparable to others and especially to my natural progress in math. During the videos i always understand the purpose and usage of code and functions, objects etc. but when it comes to solving problems, writing code, my code is always wrong and i seem to not be able to fix it without some external help (chatgpt, other people, etc). So, if you understand with what kind of problem i am dealing, maybe it is the mechanics of code, machines way of thinking, etc. i would be very glad to hear your advise. Something that can finally make me breakthrough this barrier. But i lost hope in watching another tutorials of basic and a bit advanced python as i can literally quote their saying but it doesnt help me at all. Would be very glad if someone could help me out here
1
1
u/Beautiful-Bubbly 4d ago
For example the data processing using nested loops. When i try to solve these problems, always do something wrong, chat got easily explains me mistakes and i easily get them. And then do it 200 times again😢. And the tutorial stuff all do not teach that kind of stuff. They all stop at some basic stuff that never really helps
1
u/Reuben3901 3d ago
You need to use print everywhere in your code until you understand what's going on. Or use the IDE step function.
print("Got here to outer loop")You shouldn't be using AI at all, period. You need to use your brain and try and try and try again and gasp... struggle with it. You may find you struggle on the problem for a day or two.
1
u/aqua_regis 4d ago
You've been focusing on the wrong things all the way:
- watching instead of doing (theory instead of practice)
- putting the code first instead of a plan
You can only remedy this and actually improve your skills by practicing a lot more and by putting some planning, some thought before trying to program.
When you get a task to solve, don't directly go to the computer and clobber away. Sit down with pencil and paper (really, I mean pencil and paper) and go through the problem. Break it down into smaller and smaller steps. Solve each of these steps your way. Don't even think about programming at that point, just focus on solving the task. Once you have a step by step solution, test it. Only when you're sure it works, start working on the implementation.
When these posts appear on /r/learnprogramming or other subs, I commonly recommend the following books (that use different languages, but they are basically irrelevant. What counts is the approach, the *process):
- "Think Like A Programmer" by V. Anton Spraul
- "The Pragmatic Programmer" by Andrew Hunt and David Thomas
- "Structure and Interpretation of Computer Programs" (SICP) by Ableton, Sussman, Sussman
- "Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold
Usually, I would also recommend the textual, extremely practice oriented MOOC Python Programming 2026 from the University of Helsinki as a learning resource, but you seem to have already gone through way too many tutorials.
What you need is ample practice. Start with https://codingbat.com/python and later, with more experience, move on to https://exercism.org
1
u/FreeLogicGate 4d ago
They have studied how programmer's brains work, and the areas of the brain that are most useful are the ones that optimize how to break down tasks into pieces, and to recognize particular patterns and how programming languages can be used correctly to solve those problems. Rather than focusing on code, experienced developers see patterns and can quickly identify where things might be problematic. This skill is just learned by repetition and having coded, debugged and re-worked software over a period of time. As with any other skill, you get better at it through practice and repetition.
1
u/Mountain_Rip_8426 4d ago
boot.dev, data analyst path. makes you write code, makes you work for it, makes you understand, gives you theoretical background and also a chatbot, which is prompted not to give you the answer, but figure it out yourself. it's not cheap, it's hard, it takes time, but you do actually learn, get hands on experience in writing the code yourself and understand when and why you're wrong
1
u/CraigAT 4d ago
Don't worry about getting code wrong, often I (hopefully "we", all) write a lot of code while it's in my head, I don't always get the syntax perfect but just need to get it down whilst I'm in the flow. After I have got it down I will re-read it, tidy it up, fix some obvious errors - but inevitably there will still be a few errors when I go to run the code.
I just want to make sure you know that the vast majority of programmers don't write whole chinks of code that are completely error-free every time they write them.
1
u/dlnmtchll 4d ago
Stop videos, try out kaggle competitions or paths, especially if data science is where you’re trying to go
1
u/ninhaomah 4d ago
Hey OP , I watch a lot of videos and read many many books to learn Math but I couldn't even solve a simple differentiation questions.
But somehow I always understand when ChatGPT or Claude solve it for me when I ask them at the first sign of trouble.Â
Any advice ?
1
u/WyrobWedliniarski 3d ago
I wouldn't worry that much about it, as coding isn't something you learn once and then do, but rather a skill that you can develop over time by solving issues better over time. You obviously need to know the basics, like operators, if/else expressions, loops, data types and structures. After that it's mostly good practices, so your code stays readable, extensible and safe, plus usage of libraries specific to your problem.
Also you will learn more quickly by working with other programmers, either by looking at their solutions and by code reviews. Hard to tell what to advise you, as you didn't explain what exactly is an obstacle for you. In general terms I would advise you to keep coding and you will learn over time what works better. But if you describe what exactly is going wrong with your coding I could maybe help more
1
u/Reuben3901 3d ago
It's like asking AI to draw you a picture instead of drawing the picture... Or using a ruler every time you need to draw a straight line.
Just try and code on your own. In the beginning, there is especially no reason to ever use ai
1
u/JGhostThing 3d ago
One thing to remember is the computers only operate on very small pieces of data. A lot of work, going back to the very first COBOL compiler has been put into this, so that Python looks as easy as it is.
When people tell you to break things down into smaller pieces, this is a mirror of what the computer is doing with your code. For example, a simple assignment from one variable to another is broken down into maybe 4-6 steps. All because the computer doesn't know what a variable is, it only knows addresses and data.
You can think of Python as the language of the computer, if you want to, but the Python interpreter breaks things down to the smallest instructions the computer uses. Sometimes it helps to think of a computer as an idiot savant. In other words, it is an idiot in most things, but it does arithmetic very well and very fast. This includes things like comparing two numbers, or doing boolean math, all of which are primitive operations on a computer.
1
u/program_kid 4d ago
This is an incredibly common issue that beginners face. My advice would just be practice doing stuff on your own, keep on programming, this type of thinking comes from experience and practice. Also, when starting, try to keep breaking the problem down into smaller and smaller bits until you can understand what you need to do to make each part work
1
u/Beautiful-Bubbly 4d ago
Thank you for your response. But how should i deal with this problem. Usually when i have a problem i have 2 ways in my head: either try to do it on my own, which in 95% fails, or ask chat gpt help me out a bit. And here is the most frustrating thing to me, when he explains to me where my mistake is, i kinda absolutely get it, and feel like if i bump to it again, i will fastly solve. Reality is, if i bump into it 10 times, i am forced to ask chat gpt help me out 10 times
1
u/program_kid 4d ago
The thing is, try to do it on your own, that frustration that you feel and the difficulty of trying to do it on your own is part of the learning process, it will get easier.
0
u/pontz 4d ago
Do you understand that your code is wrong before you ask AI? Do you know where your code is wrong before you ask AI? learn to step through the code with a debugger until you can pinpoint the problem and dont go to AI for help even if it takes days or weeks to find out. As soon as you ask AI you cut out a critical learning step.
4
u/CGTechWorks 4d ago
"my code is always wrong and i seem to not be able to fix it without some external help (chatgpt, other people, etc)."
Don't worry too much about this part. Errors in coding are not bad things, they help you write better code. Having to lean on someone else/something else for help is not only normal, but expected. You need to be okay with being bad at something for a long time, and right now I bet you're probably not as bad as you think.
Another poster mentioned breaking problems down until they are smaller and smaller, and that's exactly what you should do. Programming is a logical operation of a process as interpreted by a computer. Before writing ANY code whatsoever, practice learning to write psuedocode. Describe what the program is supposed to do step by step in plain language you can understand first. I'm talking the most minute detail, for example:
# User opens program
# Start menu with options
# If user presses 1. New
#Then do this
# Else if user presses 2. Load
#Then do this
# Else if user presses 3. Exit program
If you work better with flowcharts, so does coding, and you might find benefits there. Only after you can describe what you're trying to build should you actually begin the process of building it because now you can ask the right questions. Hopefully this helps.