I am struggling in my first python class. Does this mean the computer science track isn’t for me?
I have a good grade in the class thanks to the help of a tutor, but I feel like the information just isn’t clicking like it should be. I struggle doing any of the assignments on my own. There is only one week left in the class. Has anyone else had this struggle and went on to have it really click or am I hopeless? Loops really confuse me and those seem to be the basis of everything.
141 comments · 93% upvoted · other discussions
I would be more worried if you were not struggling with your first class. Maybe try thinking of solutions in pseudo code first.
E. G. You want to print the numbers one through four. Easy
Ok, but now you want to print one through four hundred... It might be easier if we could just tell the computer to reuse the print command
But what is x? And is it going to print the same thing 400 times? This needs more definition, and should be broken into smaller steps
And that right there would be a "while" loop. Not the best solution, but you can better understand the process. We would need to move the steps around a little bit too.
It might look like this
You may notice the psedo code has an instruction to go back. This part happens "under the hood" when the end of the "block" is encountered. The end of the block is when the code is no longer indented.
But for a loop that counts sequentially, we typically would want to use a "for" loop for this process.
This solution might look like this
This needs some explanation though. The range function starts at the first digit (1), and continues until it reaches the second digit (400). The third digit is how much to increment (by 1).
But since incrementing by one is the default, we can simplify by writing
But then you might run this code and realize only 1 through 399 printed. That is because I made a mistake. With range, the first number is inclusive and the second is not. We need to type 400+1 or 401, so range stops at the right spot. A lot of it is trial and error :)
I'm sure this has been explained better than I have here, but I just wanted to show how thinking in pseudo code can be more beneficial to learning how to program than memorizing syntax.
I hope this helps! (and I hope I formatted this OK!). Best of luck to you on your journey!
Edit: Thank you all for the kind words! And awards!! It makes me happy to know that any of you found this helpful 😊 Programming is often arduous and is always a neverending journey. The best we can do is to try helping one another on our way.
Dragon20C 20 points · Mar 2021
I love this, I also was confused when I started learning python but after I say 6 months it all clicked for loops, normal loops if statements, I understood it all, OP if you read this keep going I also fell in a loop of giving up but I continued, I was more interested in pygame then python it's self but it was fun all together.
Honigbrottr 4 points · Mar 2021
Atm my gf trys to learn aswell and i see myself how i struggeld with loops. But yeah just keep on going the klick will come i cant tell you why but theres a moment where you will just think "oh ok i understand" and thats it xd.
[deleted] 40 points · Mar 2021
Not OP, but I appreciate the effort man. Have a nice day.
deanotown 10 points · Mar 2021
Hey thank you for taking the time out and posting this, I’m also learning Python so this sort of information is invaluable. Thank you.
worthy_sloth 10 points · Mar 2021
I mean WOW! This is excellent
load 3 more replies →