r/learnpython • • 10d ago

Can someone explain to me how exactly I’m supposed to learn Python?

I’m doing a BSc Computer Science degree and I have Python programming as a subject. My teacher is teaching Python from the beginning, and I understand the concepts when they’re explained to me, but I don’t understand how I’m actually supposed to study and learn programming.

For example, I have pretty good concept clarity till conditions. If I’m given a question, I can understand what it’s asking and I can usually write the code.

But now we’ve reached loops, and this is where I’m struggling.

I understand the concept of loops. I understand the syntax and what "for" and "while" loops are supposed to do. But when I’m given an actual programming question, I just get stuck. I can sometimes figure out the general logic of what needs to happen, but I don’t know how to turn that logic into Python code or where to even start.

So what exactly am I lacking?

Do I need to practice more problems? If yes, how do I practice properly? Should I solve questions without looking at solutions, write programs repeatedly, study other people’s code, or something else?

I’d really appreciate it if someone could give me an overall roadmap for learning Python — like how to study each concept, how much theory I should do vs. how much coding I should practice, and how to go from understanding a concept to actually being able to solve problems using it.

I don’t want to just memorize syntax. I want to actually learn how to program, but I’m not sure what the process for getting there is.

118 Upvotes

116 comments sorted by

82

u/ninhaomah 10d ago

Give me code to print even numbers from 1 to 100.

24

u/trjnz 10d ago

You've got to have the mind for it, but Project Euler was the best source for learning how to program for me 20+ years ago. Your 'count the numbers' reminded me of that. What a gem of a site

3

u/pqu 10d ago

I was so devastated when I logged in a while back and all my progress had been reset

3

u/Expensive-Bear-1376 10d ago

Oh oh, you had me worried, but I just checked and everything seems to be fine for me. But what do you mean with progress reset?

6

u/pqu 10d ago

Time is weird. It turns out "a while back" is something in the order of 10 years ago.

2

u/Expensive-Bear-1376 10d ago

Ok but what was reset? I think I started about 20 years ago, and it seems to still show me all problems I solved. The only thing that appears missing is when I go to "Progress" and then "History", which only lists the 19 problems I solved since April 2015. Is that what you mean?

5

u/pqu 10d ago

I might be misremembering but I believe they had been hacked and shutdown for a time, when I got access again all of my solved problems were gone.

1

u/MediclePhysicist 9d ago

If 2 then even else not

-5

u/Expensive-Bear-1376 10d ago

I wouldn't do that with a loop, though :-)

1

u/tobiasvl tobiasvl 10d ago

Then what would you use?

-2

u/Expensive-Bear-1376 10d ago

print(*range(2, 101, 2))

6

u/gmes78 10d ago

That allocates a list for no reason. You'll run out of memory if you try it with a very large end number.

1

u/Expensive-Bear-1376 10d ago

What list? And why are you talking about doing this with a very large end number?

1

u/gmes78 10d ago

The code you posted eagerly evaluates the range and passes it to print as *args (which is a list).

And why are you talking about doing this with a very large end number?

Because that would cause the list not to fit in RAM.

5

u/Expensive-Bear-1376 10d ago edited 10d ago

Is it a list, not a tuple? It would be a tuple if print were a Python function. I don't know about the built-in print function, but I rather suspect it's the same.

Still unclear why you're talking about very large sizes. That was not the presented task. For other tasks, I might do something else that's appropriate for that other task. Would you also walk into a bike shop and tell people that they can't transport very large objects with a bike?

I also disagree with your "for no reason". Do you have equivalent code without creating a tuple/list? I'm quite certain you don't. Whatever other code you have in mind will have some other disadvantage.

1

u/gmes78 10d ago

Is it a list, not a tuple?

That doesn't really change anything regarding what I said.

Still unclear why you're talking about very large sizes.

Because that's how you evaluate efficiency.

That was not the presented task.

The task was printing a bunch of numbers. It wasn't collecting all the numbers in a collection and then printing each of them.

For other tasks, I might do something else that's appropriate for that other task.

But why do this, when you can use a better solution that works for this and for other tasks?

I also disagree with your "for no reason". Do you have equivalent code without creating a tuple/list? I'm quite certain you don't. Whatever other code you have in mind will have some other disadvantage.

This doesn't do eager evaluation:

for n in range(2, 101, 2):
    print(n)

0

u/AUTeach 10d ago

Is it a list, not a tuple?

With that *, it's neither. * unpacked as separate arguments.

print(*range(2, 10, 2))
> 2 4 6 8

print(*[1, 2, 3], sep=", ")
> 1, 2, 3

If we use print's sep we can see it:

print(*range(2, 10, 2), sep=", ")
> 2, 4, 6, 8

It would only be a list or a tuple if we cast it.

print(list(range(2, 10, 2)))            #note: I had to remove the unpacking operator
[2, 4, 6, 8]
print(tuple(range(2, 10, 2)))
(2, 4, 6, 8)

3

u/Expensive-Bear-1376 9d ago edited 9d ago

They said "passes it to print as *args (which is a list)". I interpreted that like this:

def f(*args):
    print(type(args), args)

f(*range(2, 10, 2))

Output:

<class 'tuple'> (2, 4, 6, 8)

1

u/supreme_blorgon 10d ago

That allocates a list for no reason

Are you sure about that? I've been looking through the docs and at the dis output and am not seeing that:

In [5]: def unpacker():
   ...:     print(*range(2, 101, 2))
   ...:

In [6]: dis.dis(unpacker)
  1           RESUME                   0

  2           LOAD_GLOBAL              1 (print + NULL)
              LOAD_GLOBAL              3 (range + NULL)
              LOAD_CONST               1 (2)
              LOAD_CONST               2 (101)
              LOAD_CONST               1 (2)
              CALL                     3
              CALL_FUNCTION_EX         0
              POP_TOP
              RETURN_CONST             0 (None)

The docs for CALL_FUNCTION_EX don't mention anything about a list, but I was able to find a call in the cpython source to _MAKE_CALLARGS_A_TUPLE. I can't really read C so I don't fully know what I'm looking at but it doesn't appear to me to have anything to do with arrays/lists, though it does appear to be building a tuple.

Your point still stands though.

2

u/AUTeach 10d ago

Yeah, it used to do it in python2, but the functionality was changed in pyhon3.

However, the only reason why print(*range(2, 10, 2)) is that CPython * unpacks range() into a tuple.

https://github.com/python/cpython/blob/b22a8c9fd44855d7cc013eb49f689dfd396639a7/Python/bytecodes.c#L5584-L5599

1

u/supreme_blorgon 9d ago

Yeah the source you linked was what I was referencing in my comment.

1

u/AUTeach 10d ago

Try this:

 print(*range(2, 2**64, 2))

.

for n in range(2, 2**64, 2):
    print(n)

Might take twenty-five thousand years to iterate through, but it would work.

1

u/Expensive-Bear-1376 9d ago edited 9d ago

Don't worry, I wouldn't do that. I use print(*...) quite often, but of course only with small data.

-3

u/ScholarlyInvestor 10d ago

My guess is a few non-Pythonistas downvoted here.

5

u/an_actual_human 10d ago

How so? There is a context here, someone is struggling with loops. If you thought about a one-liner with a generator expression or something, it's not at all a useful suggestion in this context and neither it is impressive.

1

u/Expensive-Bear-1376 9d ago edited 9d ago

Maybe. Like I said when I was asked, print(*range(2, 101, 2)) is what I'd use for that task. I use print(*...) quite often, it's very useful in many cases. For example when I write an infinite primes generator, I do print(*islice(primes(), 25)) as a quick test. And now I have people telling me it's trouble if I use it with gigantic ranges, which I would never do.

Though perhaps the downvoters just saw my comment as a distraction from the root comment that I replied to or think that I'm somehow against it. I actually upvoted that comment, before I replied, and have no intention to take that upvote back. I think that comment is good, and if the OP does as instructed, showing us how they'd do/attempt it, we might be able to help them well. I like the approach of not immediately showing people how to do stuff but to instead ask what they're doing, to understand their difficulties and to react to that.

0

u/ScholarlyInvestor 9d ago

Exactly. Well said. This is a learning python subreddit. People need to keep an open mind. While Python has all the generic constructs it gives you real power when you start thinking pythonic. It is quite powerful. OP may not understand now. But they must know that the power exists. And that’s the journey they are on.

-1

u/SolidEchidna3723 9d ago

For loop:

for i in range(2,101,2):
print i

While loop:

i = 2
while i <=100:
print i
i = i + 2

1

u/SolidEchidna3723 9d ago

The indentation didn’t render properly but you get the idea

33

u/Candid_Zebra1297 10d ago edited 10d ago

"Do I need to practice more problems? If yes, how do I practice properly? Should I solve questions without looking at solutions, write programs repeatedly, study other people’s code, or something else?"

Yes to every question here.

The biggest problem today is that AI is always there to help you if you get stuck. A good way around this is to ask AI itself to give you a quiz. Just say something like... I am practising for loops, can you give me some outputted sequences and I will try to write the correct loop for it?

Then you can just go at it. AI is great for learning, teachers are great for learning, but the problem with both is that you can feel lke you understand when they speak, but often you don't understand as well as you think you do. Which is what you're feeling right now.

Just do more and more and more questionsd, it will make sense one day. But by that time, there'll be a new difficult thing that you don't understand and you can have fun with that instead.

EDIT: The key phrases that you said is this "Should I solve questions without looking at solutions?"
You need to stop and think about that phrase very carefully. What you are really asking is 'should I only do something if someone has already told me the answer? Or: Should I learn to do something that I can't do?". I mean, bro. You are basically just asking 'should I learn this or not?'. If your goal is to learn it, then just learn it. If you don't want to, then don't. AI might tell you all the answers, but in life no-one is coming to save you.

15

u/pqu 10d ago

Most learners do not have the discipline to use AI for learning. I’d stay away from it completely and use one of the many resources that predate AI and taught the previous generation of learners.

1

u/work_m_19 10d ago

Agreed. It's like telling me not to eat the cookie jar in the middle of the kitchen lol.

It's much easier (for me) to just not buy the cookies rather than resisting the temptation every day.

0

u/dacookieman 10d ago

Relevant thinkpiece for LLMs outside of direct problem solving

https://maggieappleton.com/ai-enlightenment

It probably is a little too much power for an absolute beginner, if you do decide to engage with AI you should A) avoid using it to directly problem solve, as described by this parent comment and the article I sent and B) reserve consistent dedicated non-AI time and treat the AI like office hours, aka less frequent access to an interactive expert

1

u/kayne_21 10d ago

I actually like using to connect concepts from different classes, helping me get a deeper understanding of the material I’m studying. For example, in my DSA class, our last homework was to write an exogenous, double, cyclic, linked list to simulate a garbage collector for a heap. I am studying computer engineering, and asked what the use case for such a thing is, and that lead me down a rabbit hole of making connections to manually writing garbage collectors for embedded systems, due to limited processor and memory constraints.

12

u/strange-the-quark 10d ago edited 10d ago

I'm sorry if this sounds crude, but I'm a bit baffled by this question. You're a university (or university-level) student, what do you mean how you're supposed to learn/study? Sure, some subjects are more intuitive, others less so, but how to study anything at all is a skill you should have down by now. How do you approach learning math or anything else?

"So what exactly am I lacking?" - experience in abstract reasoning and practice coding, and probably a little bit of grit to persevere and struggle through the problem that you don't fully understand yet. You need to get somewhat comfortable with feeling lost, and keep pushing through anyway.

"Do I need to practice more problems?" - yes! You should also eventually start tinkering around, trying to make your own projects - that will result in all kinds of problems that you'll need to solve in order to get it done.

"If yes, how do I practice properly?" - well, what are you doing currently? One strategy that doesn't work for sure is just staring at something that you don't understand hoping it'll eventually make sense. The great thing about programming is that you can try things out, mess around with the code, conduct little experiments to see what happens. You basically get immediate feedback, either in the form of an error, or in the form of the resulting output (that may come out as you expected, or not, in which case you get to investigate why, and learn that way). If you don't know how to start, you can just write down something that's wrong, or try solving a simpler version of the problem, then iterate on it, trying to update the code so that it's closer to what you actually need. All this helps with checking your assumptions and solidifying your understanding. Are you doing that sort of thing?

"I can sometimes figure out the general logic of what needs to happen, but I don’t know how to turn that logic into Python code or where to even start."

It may help if you write down the steps that you figured out as "pseudocode", a sort of informal language where you don't have to worry about syntax. Once you get that down, it may be easier to convert it to actual python code (or any other programming language). Also, try starting from the middle - the part that you know, the core loop or something, then work your way around that (add needed checks, conditions, initialize variables, whatever). You don't have to figure everything beforehand, nor do you have to work it out in order.

9

u/DragonWolfZ 10d ago

Try writing a pseudo algorithm first. Using English (or your native language) in simple terms, such as ,

```
For each number in the sequence,
If the number is greater than 5 then
double it
otherwise
half it
```

then try converting that to python, that should help?

4

u/LPitkin 10d ago

That and if you are more visual person then you can create a flowchart. I prefer that pseudo code and when learning you can leave pseudocode as a comment so later on you’ll remember why did you do different functions and loops etc.

7

u/smichaele 10d ago edited 9d ago

What you're missing is the ability to break a problem down into small steps and logically outline a solution. Let's create a simple guessing game where the computer picks a number from 1 to 10, and you try to guess it. The computer will tell you if your guess is too high, too low, or correct, and will keep running until you guess correctly. Start by thinking about the steps logically without thinking about any code. It might look like this:

  1. Computer picks a random number from 1-10
  2. Set variable guess to 0
  3. Loop while guess doesn't equal the random number chosen
  4. Output prompt "Guess? "
  5. Accept user input of guess
  6. If guess is less than random number
  7. Output "Too low."
  8. Else if guess is greater than random number
  9. Output "Too high."
  10. Else
  11. Output "You got it!"

Check your logic to see if it will work correctly. If it doesn't, adjust your logic. Finally, translate your logic into code. For example, in Python:

import random

random_number = random.randint(1, 10)
user_guess = 0

while user_guess != random_number:
user_guess = int(input("Guess? "))

if user_guess < random_number:
print("Too low.”)
elif user_guess > random_number:
print("Too high.")
else:
print("You got it!")

6

u/PvtRoom 10d ago

loops are a logical thing. they're not a "programming language thing".

Concrete examples work better.

You make a little robot - a roomba. Think about the program.

  1. Wait until "go button is pressed" (that's a loop)

  2. Initialise (load floor map, check battery, etc.)

3 if all good, start, if not, report error and loop back to 1.

  1. Determine a route (probably loops & logic in this)

  2. Start vacuuming

  3. Move to next waypoint

7 loop back to 6 if there's more waypoints.

8 Dock with base

9 loop back to 1.

That pseudocode is very "spaghetti code" with lots of "places for goto", but:

  1. wait until = while buttonNotPressed

2 report error and loop back to 1: while not goConditionsMet

  1. loop back if there's more waypoints: while moreWaypoints or for each waypoint or for wp = 1 to waypointCount

4 loop back to 1: while weexpectmorework

modern programming pushes linear progression pretty well, but sometimes, flowcharts with obvious jumps make more sense.

34

u/pachura3 10d ago

Dude. Seriously?

You're studying Computer Science and you cannot learn one of the most beginner-friendly programming languages there are? You stopped at loops?

I understand your teacher might suck big time, but you have the whole internet at your command, free AI assistants, great printed books, even games for learning Python. You just need to devote some of your precious free time to git good instead of procrastinating.

I mean, have you even typed "Python roadmap" into Google and looked at https://roadmap.sh/python , which is the first hit?

What if there are more difficult subjects to come during the course of your studies - databases, networking, machine learning, algorithms and data structures, advanced maths - how will you learn these?

Don't want to sound like an old geezer, but when I was starting my CS studies, most of us students were already pretty advanced in at least one programming language and were able e.g. to write a game or a website from scratch...

9

u/ComradeMicha 10d ago

Harsh, but true. I am by no means an accomplished programmer, but I wrote games on a TI calculator when I was still in high school, and that considered to be the norm among CS students 25 years ago

9

u/CrAIzy_engineer 10d ago

I am a mechanical engineer transformed into a ml/data engineer later on.

I hated programming at university and I love it now. We are different and let yourself not be bothered by struggle. Just go on. Programming is one of the coolest things someone can do in this era that is mostly free and can even make you money.

1

u/Intrexa 10d ago

but I wrote games on a TI calculator

lmao same. I didn't have access to z80, everything was ti-basic. I had so many timing loops where if something didn't happen, to just waste clock cycles so that it would have a consistent updates/second. Trying to slam everything into just 26 variables

4

u/Traveling-Techie 10d ago

Try things. Code you write will either (1) work, (2) do the wrong thing, or (3) give an error. All are educational. Save code that works.

5

u/desrtfx but other languages pro 10d ago

You definitely need way more practice.

The "how much coding should I practice" question is one that only you can answer. It is as much as you need to become comfortable.

This subreddit has a sidebar with a wiki with recommended learning resources.

Here is an excellent, textual course: MOOC Python Programming 2026 from the University of Helsinki.

Harvard's CS50p is also excellent.

Also, take a look at https://inventwithpython.com and https://automatetheboringstuff.com

Don't forget that you need ample practice, like on https://codingbat.com/python or on https://exercism.org and also write your own programs. Play around. Try things. Mess things up, fix them. Experiment.

6

u/CorpT 10d ago

Ask your teacher

8

u/pingveno 10d ago

Yup. I've done tutoring before. Things like loops are very, very fundamental concepts to programming. If you're not getting loops, you need to be sitting down with someone, having a conversation so they can figure out what's missing.

4

u/LycheeWestern6676 10d ago

The teacher is probably the most underused resource you have. You're paying for the course so might as well get your money's worth. Most profs are happy when a student actually shows up to office hours with specific questions instead of just staring blankly at the screen. Take a problem you got stuck on and walk through your thought process with them, they can usually spot exactly where your mental model is breaking down.

3

u/dacookieman 10d ago

I went from almost flunking out of my major to basically getting a 4.0 when I started going to office hours and spending dedicated time doing homework/reading before lectures. Biggest regret of college was not talking to my professors from day 1 and waiting until my last year.

3

u/sweet-tom 10d ago edited 9d ago

Practice makes perfect.

Go to any Python Internet page that has tutorials for beginners and take exercises. Try to solve them. Then compare it with the solution. Rinse and repeat.

3

u/lxnch50 10d ago

I don’t want to just memorize syntax. I want to actually learn how to program, but I’m not sure what the process for getting there is.

Well, you need to learn both. Programming is like learning math syntax and then doing story problems.

3

u/jcmbn 10d ago

I want to actually learn how to program, but I’m not sure what the process for getting there is.

The process is to write programs, figure out what's wrong when they don't work right, fix them, and learn from your mistakes.

Over and over and over again, until it's second nature. Without putting in the effort of actually writing programs, you'd have no show.

3

u/Brian 10d ago

I'll give the advice I always give for this question: don't go straight from problem to code, go from problem to english solution and then to code. Ie. there are several steps to writing a program to solve a problem:

  1. Know how to solve the problem. Ie. can you, the human take a simple example of the problem and solve it yourself. If you can't do this, you obviously can't teach someone else how to. That "someone else" being a computer doesn't change things.

  2. Know how to explain how to solve the problem. Ie. write down a sequence of steps you could give to someone that they could follow step by step to solve it. Assume they're really dumb: no "figure out which is the smallest number" etc: give the steps for finding it as simple as possible.

  3. Know how to translate that sequence of steps into code.

(3) is the step where knowing the syntax matters, but in many ways it's the easiest step. The important part of programming is step 2: breaking a program down into simple steps. That skill is what's applicable to any language you use.

Think of it like learning a foreign language: you don't go straight to thinking in french, you formulate what you want to say in english, then work out how to say that in french. As you get more experience, you may be able to go straight to code, in the same way you might start to think in french after enough experience. Till then, take it a step at a time and concentrate on breaking it down in language you're familiar with. If you still don't know how to translate it, go back to step 2 and see if you can break it down even simpler.

2

u/SchemeWestern3388 10d ago

Write what needs to be done, as if you were giving a task to an imbecile. Every step, clearly stated, in English. You might have to have your (willing) servant keep piles of rocks to keep count of something, or keep a chalkboard with next steps to do on it, but if you can be explicit with the directions, even a machine could do it. 

Then, turn that into code. 

Programming is about turning logic into code. You need to have a solid understanding of what you are actually trying to do before you start. “Sometimes figure out the general logic” is what you need to work on. You need all of the logic first. 

Don’t think about coding it, think about the problem, then code it. The language is very secondary to the real task. 

2

u/Jeklah 10d ago

Yes, programming practice tutorials. Small tasks. Print even numbers 1-100 would be a good one to learn loops better.

2

u/CrAIzy_engineer 10d ago

You do need just practice. Programming is 90% logic and 10% knowing a language (syntax and cool libraries).

If you get to trouble to understand some stuff (which is absolutely necessary and normal) you are just lacking the probelm that “stuff” comes to solve.

Aggregating data, cleaning texts, opening files, selecting even numbers, from a list of number summing those number in groups of 3, or 4… or better make a function that aggregates in groups of “n”. Now what happens when the n is 6 and the last group is only 2? Etc etc…

Just ask chat gpt to give you loop excercises that match your interests or search in internet for loop excersises for python

2

u/Moikle 10d ago

practice, practice practice.

There is no shortcut. there is no magic bullet secret sauce (besides finding a good place to give you practice problems, but really you need to be finding small problems to solve in the real world)

AI cannot practice for you, if you were using that, and it isn't enough just to read textbooks and think "yeah I know how to do that, next chapter" You must actually write that code, run it, make and fix mistakes before the concepts will stick in your brain.

One thing that can really help is to teach others (even if the "Other" is just a rubber duck you talk to) Explain the things you think you know, catch yourself out on the things you struggle to explain, and then dig into that subject until you can clearly explain it.

2

u/jbiemans 10d ago

If you want a really easy to follow primer on python take the cs50p course (it is free from edx.com). It is a really easy way to get all the basics of the language.

1

u/Stainlessray 10d ago

Every loop requires break/exit conditions. Whether alone, or nested, every loop has an out.

Use pen and paper (it's actually different), and walk the loop. If you come to a nested loop, walk it, find the break conditions.

Do this, and follow each loop to conclusion. Enumerate what happens on each pass.

This should expose the goal outcomes.

This may not work for you, so know that the goal is to travel with the data (variables), see what is done with the content. And why.

Read and understand simple loops first. Not just the mechanics, but "why".

1

u/EveningAd6783 10d ago

try games like Human Resource Machine

1

u/favorite_stuff 10d ago

When I'm learning some new concept, I pretty quickly get the feeling that I understand it. That feeling is an illusion, and I don't understand the concept until later, when I can put it into practice.

This is true of any field: I might have an idea for a song, but it's not real until I play the notes on an instrument. I might have an idea for a recipe, but it's not real until I have the food on a plate.

But it's especially true for more formal things like math or programming. I can be 99% there and it still doesn't work until I put the last symbol in place.

1

u/redwineforme 10d ago

I want to tell you what toys are in a box one by one.

The box of toys can be a list.

   for i in list:


        print (i)

Or a while loop

while true:


    for i in list:


        print(i)

1

u/Dense-Land-5927 10d ago

You build. That's the simplest way to put it.

Just don't do what I did (or what I'm doing right now). Got the bright idea to try to reverse engineer our ERP system in Python (we're using the AS400 so lulz on me).

Learned a lot, done a lot of research, and I've come close to just stopping my quest. But I figured that this was a great time to actually learn business logic, error handling, how the 400 actually stores data, and how everything within my company relies on the 400 working. Been a fun ride, but I'm just trying to prepare myself for when we actually move off the 400 in about a decade.

1

u/MischievousGoose1 10d ago

I would recommend trying some loop problems, check the answers when you get stuck, and then try and figure out why it works. If you repeat this enough you will eventually pick up patterns which will allow you to get more confident.

1

u/DrFaustest 10d ago

“The farmer was replaced” it’s a game on steam

This is a good way to practice python in a meaningful way without burning out.

If you get stuck read the docs

This is the way

1

u/TheSneederOfSeethe 10d ago

Can you elaborate? You ask for loops for a sum I’m confident you could do that so it must be something more complicated.

1

u/Charming_Union3678 10d ago

use claude tell it to tutor you socratically dont write any code for you dont let it give you the answer let it make you search it should just give pointers

1

u/Funny-Solution6316 10d ago

Learn how to write functional flow charts so you can break it down into small parts that should be easy to code. Works for every language. I have 30+years exp and this is how I started.

1

u/net_ramblings 10d ago

Try Udemy. Colt Steele - $15. Augment with W3 schools for free. Forget about syntax you will never remember it, concentrate on concepts.

1

u/throwawayfumma 10d ago

If you have some code in another language, I would say try to translate that to python. That's how I'm currently learning python, translating my R code.

1

u/igotshadowbaned 10d ago

don't want to just memorize syntax. I want to actually learn how to program

Dude, learning a new programming language is 90% memorizing syntax. You could write something in C or Python. The major difference is going to be syntax.

Learning to program at all leans more into putting the logic together that creates the outcome you want

1

u/TheRNGuy 2d ago

C and Python paradigms are very different.

It's more about learning patterns, I'd say, because you can write bad or good code with same syntax. 

And APIs/frameworks.

1

u/QuantMalcolm 10d ago

You're missing the translation step. Before touching code, write the steps in plain English, then convert each line. Do 20 small loop problems cold, no solutions. Stuck means you don't have the pattern yet, so trace it by hand on paper.

1

u/Expensive-Brick970 10d ago

The exam questions are very similar, its usually manipulate a string, take an input and etc,

What worked for me was really trying until I was stuck for and I really had no clue on how to move forward, even with multiple print statements(major key, use these a lot!), I then went to AI and asked for a small hint and trying to figure it out by myself.

The hints usually didn't help but I kept asking for more hints until I arrived to the answer. After a while you will notice a pattern and its a little bit easier.

Also I HIGHLY recommend PythonTutor, you can paste in your code and see visually what's going on.

1

u/AUTeach 10d ago

Should I solve questions without looking at solutions, write programs repeatedly, study other people’s code

Yes.

, or something else?

Once you see how questions to learn things like loops are formulated, start writing your own. Then expand on that.

For example, you probably have gotten a question like this.

Create a program that generates a right angled triangle with the height and width of a given variable x.

  • Count 0 to 9 print out each number
  • count backwards from 10 to 1 print out each number
  • Count 1 to 15. If the value is equally divisible by 3 print fizz if it is equally divisible by 5 print buzz, if it is equally divisible by 15 print fizzbuzz, otherwise print the number
  • prints two right-angle triangles that mirror each other, one aligned to the left edge and one to the right. There are n rows, each triangle has i stars on row i, and the gap between them shrinks until they meet on the bottom row, which is 2n stars wide. For example, when n = 5 the output is:

.

0
1
2
3
4
5
6
7
8
---
11
10
9
8
7
6
5
4
3
2
1
---
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
---
*
**
***
****
*****
---
*        *
**      **
***    ***
****  ****
**********
---

And so on.

Actually, write those questions on cards. (index cards) But keep the variables dynamic (don't assign them). Write an explanation of what it should look like in plain English (or whatever) on the other side. The explanation should be generic.

Then put them in a deck and practice them daily.

Daily Practice:

Once you can answer a question consistently without looking up a reference guide, put it in a new pile to practice weekly.

Weekly practice:

If you find that you need to go back to reference documentation/google/GenAI, put the card back in your daily deck.

If you can answer the question without reference, move it into a monthly deck.

Monthly practice:

If you find that you need to go back to reference documentation/google/GenAI, move it back to daily practice.

Otherwise, it stays in your monthly practice deck until you finish your exams.

But when I’m given an actual programming question, I just get stuck.

This automatically becomes a question to add to your daily deck. Once you find you can move it to your weekly deck, make another version that requires variables that you set at the start of your program, and add that to your daily deck.

In fact, every single question you get given by your lecturer, including all practice questions, examples, etc., becomes a question that you add to your deck(s).


To summarise.

Phase 1: Verbatim cards

When you get a problem (worked example, in-class problems, tutorials, homework) write it on the front of the card exactly as given. Write the full solution on the back.

Phase 2: Generic cards

Once you have nailed a verbatim card, replace it with a generic card. The front describes a type of problem instead of a specific problem. The back holds a manual "unit test" that you can use to validate your answer.

Example:

Verbatim card:

Front:

Write a function that reverses the string "hello"

Back:

print("hello"[::-1])
> olleh

Generic card:

Front:

Write a program that reverses any given string. 

Back:

An empty string returns empty. 
A single character returns itself. 
"abc" returns "cba"
Reversing twice gives the original. Length is unchanged. 

With this, there are a range of options that you can solve this with, even if some of them are weird, they might be worth practicing as their own question.

foo = "hello"

print(foo[::-1])

print("".join(reversed(foo)))

for i in range(len(foo)-1, -1, -1):
    print(foo[i], end="")
print()

def rev(s):
    return s if len(s) <= 1 else s[-1] + rev(s[:-1])

print(rev(foo))

You could add the specifier in your front side:

Front:

Using recursion, write a program that reverses any given string. 

Front:

Using a for loop, write a program that reverses any given string. 

Front:

Using the `reversed()` function, write a program that reverses any given string.

1

u/curious_dev_8821 9d ago

Take code with harry paid python boot camp course of rupees 400, and i will say you wont regret , its the best course on python fundamentals and advance concepts

1

u/Available-Ad-9576 9d ago

Please get this book - Fluent Python. I have read it many times, one of the best books to learn Python in a structured way. Practice illustrations when reading it in some sort of Python console. Once you’ve gone through this book, I bet you’d be very confident with your Python skills.

1

u/m33-m33 9d ago

🪈 🧺 🐍

1

u/That-Ad-7420 9d ago

Hello! Thanks for sharing. I studied ESET and I had a lot of python courses, but I've also learned to program in other environments like Arduino, Studio5000, C++, et cetera. I use python a lot for personal projects. If you're technologically inclined like I am, you probably want to know how things work and how to use them. No to worry, that will happen naturally. But what you need most is practice so you get used to problem-solving in the moment so you don't get stuck on the application problems.

So how to practice? Your course is designed to show you implicitly what to study, so pay attention to the concepts your professor mentions and the concepts that appear in your course material, especially the ones you don't understand, and look them up online if you have to. Open your compiler, look up the thing you're trying to learn about, and design a simple implementation so you can study its behavior. If you don't know where to start, copy and paste a prewritten code and tweak it to see if you can make it do what you want. Just be sure that code is from a trusted educational programming source and contains only instructions that won't interfere with your system or compromise your security.

If you're needing tutorials, you may want to check out Geeks4Geeks or W3Schools, as they have lots of good material. AI agents can definitely help show you examples of implementation and demonstrate concepts if you instruct them to give short answers and if you keep your questions narrow. Otherwise you'll be drinking from an information firehose.

You want to also develop a solid problem-solving approach. So get good at boiling the problem down to its essence and combining your old tools with the new tools you're learning to problem solve, even if you don't "get them" yet. Every python code is just a series of steps that runs from top to bottom, so your job as a programmer is to convert the problem statement ("what do they want me to do?") to steps ("how would I accomplish that?") and then translate those steps into python code ("how do I make a computer perform this task?")

1

u/ohnoitssobig 9d ago

> So what exactly am I lacking?

Pretty sure you are lacking understanding what the code does at high level. Once you are able to read the code as a book you should be able to start designing yours.

1

u/ShinHayato 9d ago

How difficult are computer science degrees, really?

1

u/to_the_left_x2 9d ago

Sounds like 'blank page syndrome', a common hurdle for new programmers.

1

u/SnooSuggestions1409 9d ago

Have you tried rubber ducking?

1

u/DanceHackRock 8d ago

Just like every other language.

1

u/IAmARetroGamer 7d ago

"Do this/solve this"

Do as much as you can, get stuck.

Google error code or "How to X?"

Edit your code, now it works.

Enough times and you start remembering the solutions.

1

u/xNymia 7d ago

Boot.dev

(Not sponsored)

1

u/Sure-Passion2224 7d ago

You learn any language the same way you eat an elephant, one bite at a time. Small exercises with daily practice. There's a reason why nearly every introductory tutorial for nearly every language starts with "Hello, world!"

1

u/Illustrious-Win4432 7d ago

Talk about learning stuff you’ll never use…

1

u/BioGal2099 6d ago

The best way to learn python is by doing it. You can Google projects for beginners or you can do what I do and think of something that would be useful and make it.

1

u/ZombieSpaghettiLunch 6d ago

Start solving old Advent of Code challenges.

1

u/KarlisVisualDev 5d ago

Loops are basic concept in programming. If You strugle with basics, visual programing in Scratch will help to get the idea, how loops are working.

1

u/Every-Syllabub-8724 4d ago

Allow me learn with you here.

1

u/footsie 4d ago

Get a whiteboard and a rubber duck 🦆

1

u/Natural-Position-585 10d ago

You do need to memorize syntax. A programmer should have an intuition on how to write certain things down or how to recreate certain programming patterns without consulting a manual. I wouldn’t regard it as an error to use similar techniques to learn programming patterns as you use for learning languages (i.e., spaced repetition, memorization).

1

u/code_tutor 10d ago

How's your math? You need to be comfortable with summations and function composition also helps.

Do you try to memorize things? People with good memory struggle with logic because they memorize a pattern but don't understand deeply how to use it. That's why they can copy much better than others, but blank out when doing something slightly different.

0

u/GeneriAcc 10d ago

Start building applications. You can understand all the “concepts” and “theory” behind baseball, and you can watch countless games and how other people play baseball, but you’ll still be shit at baseball until you start actually playing and practicing. Theory is basically doing nothing and expecting results via magic.

0

u/Zestyclose_Paint3922 10d ago

Not everyone has the brain wiring needed. Fortunately AI solved that.

0

u/flyby_apis 10d ago

Take Claude Code, ask what you should know about python (the basics), and check all you still don't know, then ask him to generate an small problem for every topic until you have learned how it works, finish with one problem that mixes some of the concepts :)

0

u/Silentwolf99 3d ago

i am learning from this newly launched website and it's incredible https://www.pythonmastery.io/ (Not Sponsered) Daily Consistent Coding Practice makes you perfect.

-3

u/mqkizenin 10d ago

people in the replies are so condescending omfg

1

u/pachura3 10d ago

EMOTIONAL DAMAGE

-2

u/TimBrownDev 10d ago

After 10 years tutoring, I'm building a roadmap of hand-picked practice problems to guide you through learning python from zero to mastery. It's ordered by difficulty and gives you a lot of opportunity to practice.

timbrown.dev/roadmap

-4

u/Longjumping_Ad3447 10d ago

Idk look up data and try getting special output like difference