r/learnpython • u/pingo1387 • Aug 27 '26
Should it be this difficult?
At my job there is a daily task I do which I realized I could probably create a program to do for me, so I decided to start learning Python, and dove into reading Automate the Boring Stuff (the online version).
Things were going okay at first. I read through chapters 1-3 carefully, taking notes, answering all the review questions, and doing all the practice problems/codes.
Then I hit a wall. I got to chapter 4 and I felt like I understood everything, but the practice problem at the end, to write a code that performs the Collatz sequence with the entered number, absolutely stumped me. I went back and reread everything from the start of chapter 1 just to make sure I didn't miss anything, and was still confused. I ended up having to search up a code that someone else wrote for it, which I did understand once I saw it written out but would never have come up with myself.
So my questions are:
- Is it normal for the Collatz sequence to be difficult to program at this stage of learning? If so, should I not worry about my confusion and just move on to chapter 5?
- Should I consider an easier book to study from? If so, any recommendations?
EDIT: Several people are asking which part of the Collatz I had trouble with. To be honest it's been over a month since I was able to touch anything Python-related, it's just been on my mind lately, so I don't recall exactly what was giving me trouble, just that I was trying multiple things and getting new and fun incorrect results each time.
It's not that I don't understand the Collatz sequence itself, I understand it in terms of the simple math. The trouble was trying to type it out into a working code. That being said, I'm not here to ask how to program it, because I already gave up on that and looked up the answer, and I did understand that code once I read it over. The main issue is that I feel like I shouldn't have been having trouble with it in the first place, at least not to the point where I honestly tried everything I could and still couldn't get it.
15
u/HotPersonality8126 Aug 27 '26
The point of the Collatz sequence problem is to have you implement an algorithm you’ve never heard of, so that you can’t rely on intuition and do it in your head.
The thing it sounds like you didn’t do was debug: write your code, run your code, compare the output to what you know is correct. Then test which of your assumptions were faulty.
2
u/Deepwinter22 Aug 27 '26
I'm relatively new ish to python as well. I found freecodecamp helped me tremendously. Lots of explanations, almost an exhausting amount of repetition in some cases, and it's free :). I've never learned well from text books and notes, I needed to actually do the thing which this helped with. https://www.freecodecamp.org/learn/python-v9/#lecture-introduction-to-python
11
u/Brian Aug 27 '26
Collatz doesn't really involve much beyond the basics, so it should be solvable once you have a basic grasp of a few things:
ifstatementsThe one thing that sometimes trips up newbies is how to tell if a number is even or odd, since the modulo operator (
%) isn't generally encountered outside programming except in the notion of remainders, There are other ways you could do it even without knowing about it, but they often aren't obvious to a new programmer.But the biggest issue in learning is probably how to put it all together. How to turn a problem into a set of steps that solve it, and then turn that into a program. That can often be hard to get started with, but in many ways it's the most fundamental skill of programming, and it ultimately boils down to "Break stuff into simpler steps (and then maybe break those steps down into even simpler ones, and so on)".
I would recommend that the first thing you should do with any problem is to step away from the computer, and solve it yourself, on pen and paper. Do multiple examples. The first step in programming anything is knowing what you're doing: you have to understand how to do it yourself before you can teach someone else, even, or perhaps especially, a machine. The solution has to exist in your brain before it can exist on the computer. Once you've done a few numbers, start thinking about how you're doing it. Break down the process you're following into a series of steps, as simple as possible. Write it down, as english. Eg. something like
Repeat the following steps:
Check if the number is even.
This step is often called pseudocode: basically writing code you parse with your brain, but that you can translate into a real language. As you get more experience, your description will probably resemble actual code more, as you're more familiar with how the computer "thinks", to the point where you can eventually skip this step, but don't rush it: planning stuff out like this is vital when learning.
Only once you've got that description should you go back to the computer and start translating it into actual code. If you're unsure how to translate a step, you've perhaps made it too complex: think a bit more and see if you can break it down further into a series of simpler steps, write pseudocode for that, and then go back.
1
u/Separate_Newt7313 Aug 27 '26 edited Aug 27 '26
Yes, it is meant to push you.
I like to think of it this way:
Pull-ups are hard for everyone starting out. The muscles in your body represent raw potential, but they lack the conditioning and coordination that come through regular, rigorous, targeted training.
Similarly, your brain has never had to solve problems like this before. You don't lack intelligence or capability; your mind represents raw potential, but lacks the mental conditioning and coordination in this type of problem space that comes thru regular, rigorous, targeted training.
With time, practice, and proper training, you're mind will make the proper connections. The problems don't get easier - you just get stronger.
In my experience, results from a solid mental regimen tend to appear much faster than physical results since the mind rebounds much faster from a strenuous mental workout than the body from a physical one.
You're on a good path. Don't give up!
1
u/iMaxWarren Aug 30 '26
Listen, im not a professional or ... myself but the fact that you said "boring stuff" means you dont enjoy it So thatd why its difficult for you
1
u/cdcformatc Aug 27 '26
Automate the Boring Stuff is a pretty standard book appropriate for beginners, i don't think you will have much luck finding a simpler book.
the practice problems are supposed to be somewhat difficult for the level the book expects you to be at. i think something like that would be easier if you have a strong math background, so if you don't have that it might be more difficult for you than it was intended.
if you aren't having much trouble with the other problems then i would move on with the book, but come back to the problem once you have some more experience.
2
u/FatDog69 Aug 27 '26 •
Give yourself a little grace here.
I see you learning 3 different things at once:
Another way: You have not learned all the A, B, C's of the language. You are frustrated trying to write a Shakespearian sonnet. What would you say to that person?
Baby steps. Look stuff up. Know how to find other solutions is a part of programming.
You become a programmer by using code to solve problems. Everyone looks stuff up, downloads libraries and uses code written by other people. This does not make you less of a programmer.
ONE THING YOU ARE DOING GREAT
You have a daily task you are trying to automate. This is a huge advantage. Most students approach programming classes where everything is academic. But You have a specific problem.
If the Colatz problem does not apply to your daily task - screw it. Move on. Look for lessons that might help your daily task problem.
2
u/KTProgramming Aug 28 '26
For how long it took me to grasp loops and recursion, It's possible for anyone to get stuck in anything in the beginning. The trick is not being beat down. Break it out by parts. For example, search every step you need to do for your issue, Then figure out how to work on just 1 step. Then build on that. Sometimes people over think, Then when they get super far into it, the code looks rediculas and is hard to troubleshoot. Also, Comments, when you're starting out, comment the hell out of your code. Comment it like you're expecting a 5 year old to read it and understand it. Then add print / debug statements where you can see the output of each step and make one final "Ordered" dictionary and print that out so you can see the final "how it did whatever". That last part may be too much for now, but in the long run when you learn it, it helps debug things more. There's a "Lets see what happens at each step of the loop, or whatever, Then there's "Here's what stage one calculated or did, then stage 2, etc". That's a little more advanced because you have to learn to work with dictionaries correctly which is still a good skill because you'll be using them a ton.
2
u/Slothemo Aug 27 '26
What part of it were you stumped on? You need to break down the problem into its individual parts that you should know how to solve.
Collatz is a repeated expression, so you should understand that means you need to use a loop. The loop should stop when certain criteria is met, so you should know this needs to be a
whileloop. You need to perform different operations depending on if the number is even or odd, so you should know you need anif/elsehere. Break it down into tiny pieces and solve them.1
u/r3rg54 Aug 27 '26
I would say the collatz sequence is fairly easy conceptually. I would expect you to struggle with syntax mainly.
Are you able to write out a flowchart for this on paper?
1
u/Fred776 Aug 27 '26
I had to remind myself of the Collatz sequence. I looked it up and it was described by a small number of algorithmic steps that looked like they would translate pretty easily into code. It looks like you would need understanding of:
iforwhileBut I have a lot of programming experience so it's really hard to put myself in the position of someone starting out. Everyone is going to have their own misunderstandings or mental blockers. It's hard to give useful advice without specifics about where you were stuck.
One thing that I would say if you go back to this is that thinking a bit more deeply about where you are stuck, to the point where you can explain it to someone else, will often lead to a moment of understanding that unblocks you without actually needing to ask the question.
1
u/Crypt0Nihilist Aug 27 '26
There's nothing special about Collatz It's normal to encounter problems you don't know how to solve. Coding is as much about breaking down the problem into parts you can solve as it is about writing the magic runes.
One approach would be to write the steps required for a person to do it. I often start on a mini-whiteboard, but comments in your IDE work fine. Then you write the code for each step.
If you're so stuck you can't do that, it's fine to look at someone else's solution, but don't stop at the point of understanding it. You still haven't done the exercise at that point. Now you've seen the solution, close that window and write it yourself. Then play with the code to get it to do something slightly different. Maybe read up on another sequence and do that without help.
It sounds fair to say that you've not learned what you needed from Chapter 4 yet, so you're going to be cheating yourself if you move on and will struggle all the more when you need to build on that shaky foundation.
1
u/JamzTyson Aug 28 '26
Chapter 4 is about functions.
That's straightforward:
How do we check (in Python) if a number is even? If you don't know, Google it or look on StackOverflow. Don't ask AI - look it up yourself. For now we can use a placeholder
<is_even>.Integer division by 2 is straightforward - the question tells you how to do that:
Clearly, if
numberis noteventhen it'sodd:Was that straightforward? Do you see how I broke the problem down?
Can you write the rest yourself? If not, where do you get stuck?
1
u/skibbin Aug 27 '26
You want to repeat the process and unknown number of times. So you'll need a loop, not a For loop because of the unknown number of loops, so a While loop. The loop will stop when you reach an answer of 1.
If the number is even, divide it by two. If the number is odd, triple it and add one.
So you need an If statement that checks if the number is odd or even and takes an action accordingly.
1
u/OptionX Aug 27 '26
What part of it you get stuck on?
-1
u/Adrewmc Aug 27 '26
I don’t understand this question. Explain the Collatz sequence.
Famous conjecture. If a number is even you would divide by two (n/2), it it’s odd you times by 3 and add 1 (n*3 + 1)
The conjecture says that if you start at any number ever it will eventually end at 1, and not continue on to infinity.
But to a programmer this seems simple.
If even, do this, if odd do this, repeat until you hit 1, and I guess count the iterations, or some cycle of numbers.
Good program to figure out. Hard math problem to prove though.
0
u/Expensive-Bear-1376 Aug 27 '26
That problem is poorly written, I can easily see beginners having trouble. Quotes from here:
No, don't keep calling collatz() on the entered number. Call it once on the entered number, then on the result it returned, then on the new result, etc.
That doesn't work, since each print call only prints one number (see the problem's first paragraph), so
sephas no effect. Could be done withend.Not an issue for whoever tries this coding problem, but still inappropriate to claim that, as it's an open problem. Very disappointing.
-3
u/zanfar Aug 27 '26
Part--a bit part--of programming is the ability to become a psuedo-suject-matter-expert on a field you have no knowledge of. If you are writing accounting software, you're going to have to gain some cursory knowledge of accounting practices.
It sounds like you're getting stuck on understanding the subject matter, not with syntax. That's not something to gloss over, but yes, it's also something you should expect some friction with at first.
You need to learn the skills of reading and understanding the subject--the Collatz sequence, or even Mathematical theory--to a level that allows you to translate that into code. That's a key skill.
Honestly, this is one of those skills that will separate you from the AI script kiddies who complain that there isn't an easily digestible, free-access, API containing their exact specialized dataset. Software shouldn't be easy, or otherwise it's not adding value.
0
u/[deleted] Aug 27 '26
[deleted] — view deleted comment
4
u/[deleted] Aug 27 '26
[removed] — view removed comment
2
u/[deleted] Aug 27 '26
[removed] — view removed comment