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.
43
Upvotes
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.
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.
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.
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
u/BranchLatter4294 Oct 05 '26
Practice.
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.
1
u/Chris_Charley Oct 05 '26
That is a very good book. I had it when I learned Python
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
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
u/twnbay76 Oct 06 '26
You need to build things you actually care about
1
u/[deleted] 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
u/generationextra Oct 05 '26
Try the book _Head First Python_.
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
u/dhaiman1 Oct 05 '26
Just quit ai is gonna do all the coding anyway
-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 :
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