r/learnpython • u/Comprehensive_Wolf91 • Oct 05 '26
I’m taking a “learning programming in python” class in high school and im already lost.
The first month was very easy. Inputs, basic programs and whatnot. Now its while and for statments, as well as loops and nested loops. The programs are mostly solving hard mathematical equations, and I’m not great at math and the rest of the class is very good, so I’m always behind.I am soooo lost now and rely heavily on the internet to finish my programs. Is there anything i can do outside of class to gain the same programming knowledge. The textbook were studying is starting out with python 6th edition by tony gaddis.
37
u/re_me Oct 05 '26
Sigh. I see nothing has changed in 30 years.
Thats how they taught programming when I was in high school and I assumed I was bad at programming. Now I’m a data scientist.
Practice helps. “Python novice to advanced” was a good book. Not sure if “automate the boring stuff” is still relevant. “Think Python” was probably my favourite learn programming with Python.
Those would be where I would start.
3
u/pachura3 Oct 05 '26
This is so unfortunate. I bet majority of pupils would be much more excited about programming in Python if the teacher asked them to write simple games, Discord bots, music visualizers, face recognition, monitoring crypto-market... but no, let's solve hard mathematical equations.
2
Oct 06 '26
Symptomatic advice like "just practice more" or listing entry-level book recommendations misses the immediate barrier. Stalling on Fibonacci rarely stems from a lack of general syntax exposure; it comes from not knowing how to break down state management and the execution stack. Recommending broad resources obscures that diagnostic gap.
5
u/nivaOne Oct 05 '26
Don’t let it discourage you. It takes a bit of time to see the forest through the trees.
You need to pay attention to the details of the question. It says below 4M in your example.
So for or while?
You don’t know how many times you will need to go through that loop. You do know when to stop.
The exercise practices two things: 1. for or while
‘for’ always runs at least once AND it only stops after a number of times. Because you don’t know how often. You will have to test it before you print and exit the loop, once the condition is met . Not an elegant way. So for is not a good option.
‘while’, automatically ends when a certain condition is met.
2. the use of multiple assignment aka tuple unpacking
Multiple assignment avoids the use of a temporary variable.
temp = a
a = b
b = temp + b
versus
a, b = b, a + b
The latter is what Python is about.
Writing code in less lines.
Two reflexes hence: should I use for or while. Can I avoid the use of a temp variable.
1
u/bra1n_gym Oct 05 '26
You answered the question beautifully, but then you added extraneous stuff that had nothing to do with what the person asked. python is not about using less lines of code. That's is a small part called refactoring. python is a language that is near human readable which is why it's good as a first language. The goal is write code that works and then write it neater as you learn more techniques.
1
1
u/cadenceweapon Oct 05 '26
The last bit about code style. And avoiding errors, or at least making them easier to find because of how you structure your code. That's not how you learn the mechanics of coding. Gotta learn to walk before learning to run.. once you build and scale to the point where you need to debug, or work with others these lessons will become self-evident. That or you will know why you are learning to code clean, document and build tests.
8
u/coconut_maan Oct 05 '26
Ok ,
Python is a tool to implement logic. If you dont understand what your implementing like the math's... you will never understand how the specific python implementation works.
First make sure that you understand what and why you are doing and the programming becomes easy.
Just go slow. Math is hard to understand when you dont understand and easy to understand when you understand so take it slow and ask alot of questions
2
u/GreatGameMate Oct 05 '26
All I can recommend is code code code, that’s how you get better. What exactly are you struggling with, is it the coding itself, thinking of how to implement the logic, the syntax, or the stuff you are doing with the code (hard mathematical equations).
2
3
u/nicodeemus7 Oct 05 '26
Programming is a lot of math. But the good part is it does the math for you if you know how to use it. It'll get easier, but I will say maybe try and improve your math skills, because you need them for programming.
4
u/ometecuhtli2001 Oct 05 '26
That’s heavily dependent on what someone codes for. In over 30 years of software development for web apps and systems automation, I’ve only needed math once to solve for predicted storage usage.
-3
u/nicodeemus7 Oct 05 '26
You may not be doing a lot of math with your code, but the code itself is math, and you need to understand how that math works to code effectively.
3
Oct 06 '26
I’m a swe myself. Could you please explain what math a swe must need to know to code effectively? Thank you
2
u/ometecuhtli2001 Oct 05 '26
Not necessarily, and not as a beginner. As a DBA (currently) I need to know how indexes work for efficient queries, but I don’t need to know how index data is encoded and stored on disk. That kind of under-the-hood knowledge is good to have and it’s fun digging around in the internals, but it’s not a requirement. I’m a senior DBA so I have done that, but when I was just starting out it never even occurred to me.
At OP’s level where they’re just beginning, that in-depth knowledge can wait until there gotten the hang of the language.
1
Oct 06 '26
I believe the point was that math is needed and the next comment said nothing but that math is needed again. I much rather ask what math is needed. 😂
3
Oct 06 '26
Claiming programming is "a lot of math" gives learners a false justification for struggling. Unless you are writing 3D graphics engines, cryptography, or low-level ML models, programming is logical orchestration, not mathematics. Telling beginners to study math when they struggle with control flow directly hinders their progress.
1
u/h00manist Oct 06 '26
I disagree math is needed to learn python. Math is often used as exercises for python beginner examples. I have no idea why, it's tradition perhaps. I think it just complicates things.
1
u/manymenzzz Oct 08 '26
bruh, my brother is literally a Dev Op. I can tell you right now, the only math he is using is google.
1
1
u/dariusbiggs Oct 05 '26
There are a few basic concepts in programming that are universal across almost all of them.
Conditionals, loops, basic math, Boolean logic, data types, functions, and probably a few more.
Those have plain English constructs associated with them.
Break down the problem into those constructs.
Here's some examples
If this then that (conditionals)
Do thing repeatedly (while and for loops)
Keep adding X to Y until (for loops, arithmetic)
Do F to X (function calls)
etc..
The most common math things you are likely to need are basic addition and subtraction (usually +/-), and multiplication/division (usually by 2 or 10).
1
u/bra1n_gym Oct 05 '26
best practice: while loop is when you do no know how many interactions there are, just the condition that breaks the cycle. for loop when you know how many interactions or the number of items. Think of a traffic light: While the light is red: you must stop if the light is green: you may move forward.
for signal color in [red, yellow, green]: if color == red: stop
As for nested loops, think of the data's dimensions. if it's one line or row of data, then it's a single loop. if the data is a table like a spreadsheet, then you would use 2 loops.
let's use a calendar example: while the the year is less than 2030, you're practicing python in high school.
for month in year: for day in month: for hour in day: for minute in day: do something
unfortunately, this doesn't format well.
1
1
Oct 06 '26
When asking for help with a coding problem, provide a specific example of what's tripping you up—even if it's a simplified version.
If you get stuck on an algorithm like the Fibonacci sequence, ask yourself: Could I solve this with a pen and paper? If the answer is yes, your issue isn't the underlying math—it's translating that logic into code.
Next, identify the required approach:
- Iterative: Are you required to use a for or while loop?
- Recursive: Are you required to use recursion?
If recursion is giving you trouble, the problem usually isn't the algorithm itself; it's a gap in understanding how the call stack handles execution under the hood.
1
u/Youngrasta_999 Oct 06 '26
the only to learn is to code and get it wrong and try again when it works find out why it works and repeat the cycle
1
u/h00manist Oct 06 '26
Don't be frustrated. Hack your way around the math. You don't really need it. Talk about the math problem in class.
The best python teaching books don't mention any math, zero.
Automate the Boring Stuff with Python, and Python Crash Course, are some of the most widely recommended python beginner books, and don't deal with any math.
Take your class code example, put them in chatgpt, and ask it to create a simpler example of only the *programming principles*, taking out the math.
1
0
u/ivanoski-007 Oct 05 '26
They teach python in high school now? Poor kids gonna get a terrible education because high school sucks for learning, terrible teaching model and kids who don't understand jack. Just learn the basics and wait till college
-9
-3
u/Educational_Virus672 Oct 05 '26
um you know why apps stay opeen until you press "X"? they are in a loop that repeats some code where while loops(not always) is True it will run over aand over again :
close = YourUI.ClosePressed # true when pressed
while not close: # not means it does opposite stuff
close = YourUI.ClosePressed
...another example you know how hackers do these password cracking stuff they do it using for loop,a for loop takes each item from a list(or string) and runs the code with each item over and over again
password = 1234
for i in range(1000,9999): # i means each item it is changabl to anything
if i == password : # range means it is a list of numbers
print(i)
break # ends the loop
14
u/Outrageous-Catch4731 Oct 05 '26
I'm curious how your class is solving hard math equations with mere while and for loops. I don't want to throw sources at you. Can you provide one example while or for loop exercise that has stumped you.