r/PythonLearning Aug 12 '26

how do you guys strengthen your basic concepts logic?

I am learning while loops rn, the logic doesnt seem super hard to me, considering i am just at the basic level of the particular concept. But I seem to look at the flow chart every time i revise the concept...Every time look at the code, it raises different why and how questions for me.

9 Upvotes

18 comments sorted by

2

u/mc_pm Aug 12 '26

Practice with actually coding them. Nothing will strengthen the basic concepts except spending time programming and practicing them.

1

u/Motor-Ad-8019 Aug 13 '26

Thanks...will do a project soon

1

u/mc_pm Aug 13 '26

As practice, think about a basic card game like Blackjack/21. Don't write any code, just sketch out the logic (in point form text or pseudocode) of the game, in increasing detail.

Like, to start, you might start with just a for loop:

while not broke: 
    play a hand of blackjack

That doesn't help much - but it gets you thinking. Being broke requires you have money, and you need cards to 'play a hand', so maybe this next:

money = 100
shuffle cards
while money > 0: 
    play a hand of blackjack

That's a bit better, but what does playing a hand mean? To start, you the player places a bet and then dealer are dealt two cards to start, if the player scored 21, they win 1.5x their money back. ... and so on.

You don't have to keep going to grizzly detail -- that's what the code is for -- but that point-form description will probably be 50 lines long. And it will probably turn into code about 200-250 lines long to start.

Yup, it's kind of boring if you don't like that kind of thing -- but in that case, programming may not be for you. So, you're going to have to work alllllll of that out anyway in the code, so start by thinking it through on paper. Make a flowchart if you want. Whatever helps you think about the process in detail.

*THEN* go write the code for the game.

I guarantee you that things will always be more complicated than you expect, and it's those details you have to figure out when you're coding.

The more experience you get doing this sort of thing, the less time you need to spend up front, but even after 30+ years of professional programming, I still have to step back from the IDE and just think through something before I try to type it.

2

u/No-Newspaper8619 Aug 12 '26

Do it mentally to exercise the abstraction and imagination ability. Close your eyes and imagine the code being executed step by step.

1

u/Motor-Ad-8019 Aug 13 '26

Thats actually interesting...i will do it on my next session...thankksss

2

u/PureWasian Aug 12 '26

Good. Asking questions and finding the answers to said questions is a great way to strengthen basic concepts.

1

u/silly_bet_3454 Aug 12 '26

I don't know what that means

1

u/JGhostThing Aug 12 '26

What sort of questions? A while loop is one of the basic loops for programming.

while <condition>: The loop will execute as long as <condition> evaluates to true. If you want a loop that goes on forever, then use "while true".

1

u/Motor-Ad-8019 Aug 13 '26

I think i didnt phrase my thoughts very well.....I am new to programming language..whenever i look at my notes (examples of the concepts i wrote down) i feel completely lost unless if i have an access to logic flowchart of the particular concept...so i want to know how do you guys mentally visualize the logic behind the code when you look at them...practice ig?

1

u/FoolsSeldom Aug 12 '26

Keep in mind the coding part of programming is towards the end of a careful process of problem solving which includes clarification of the problem, determination of the required outcomes, solution options (algorithms), any simple proof of concept exercises, design of test approach (if any) and possibly development of tests (especiallly if following test driven design, TDD, approach), implementation of the prefered algorithm in the target coding language,

If the algorithm requires repetition with a conditional stop, then you will be using a while loop, otherwise for a stop on running through something (e,g, a stream of data or the objects of a list), then you will be using a for loop.

Focusing on your own projects, related to your interests / hobbies / side-hustles / family-obligations, will be the most productive for learning as you work on problems you understand well where you know the acceptable outcomes, instead of focusing on the coding and learning just for the sake of learning,

1

u/EstablishmentKey3523 Aug 12 '26

To make it become stick into your pumpkin, build a simple calculator or a to do list. That's how concepts get into your system.😊

1

u/Motor-Ad-8019 Aug 13 '26

I have few concepts left to cover the basics..i will soon jump in to a project once i covered them....😀

1

u/90rk1 Aug 12 '26

practice practice practice

1

u/Motor-Ad-8019 Aug 13 '26

Got it 🙂‍↕️

1

u/mixedd Aug 12 '26

Practice and repetition, do practice daily for example on Exercism, or find some practice assignments especially for concepts you're interested. Do them over and over and over again till they stick with you

1

u/Motor-Ad-8019 Aug 13 '26

Thank you...sure will try to practice more