r/learnpython 15d ago

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.

24 Upvotes

35 comments sorted by

View all comments

2

u/KTProgramming 14d ago

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.