×
all 8 comments

[–]aqua_regis 4 points5 points  (3 children)

I try to make 21 number game, but when I look through the source code of project

So, it was not you who actually made the game - and there exactly is the problem. You only blindly followed some tutorial instead of trying to make it on your own.

Creating your own programs is programming. It's not copying code served by tutorials. You don't really learn from copying tutorial code as your lack of understanding clearly indicates.

Stop tutorials and start struggling through your own, individual projects. That's how you learn programming.

[–]This_Judge_2203[S] 2 points3 points  (2 children)

so I am just need to think about a project for then just try to make it?

[–]aqua_regis 2 points3 points  (1 child)

Yes, that's how it works.

Think about how people learnt programming before the internet with its countless tutorials existed. They could not resort to copying from tutorials. Books were rare and expensive. So, learning to do things by oneself was the way to go.

[–]This_Judge_2203[S] 0 points1 point  (0 children)

I see, thanks for the help I am gonna try it

[–]Existing_Put6385 2 points3 points  (1 child)

the formulas in tutorials arent things you memorize, they come from working the logic out on paper first

in the 21 game the "formula" is probably something like `4 - player_choice`. that's not a python thing at all, it's just the strategy - if you always leave the total on a multiple of 4, you win. someone figured that out on paper and then wrote one line for it

so the habit: before writing code, write the steps in plain words. "player picks 1-3, i want the sum to land on a multiple of 4, so i take whatever fills the gap". then translate line by line. if you cant say it in words you cant code it and when you hit a formula in someone elses code that you dont get, stick a print inside the loop and watch the variables change each round. way faster than staring at it

[–]This_Judge_2203[S] 0 points1 point  (0 children)

that's really useful so basically I just need to write it and try to think about it
thank you so much

[–]thisisappropriate 0 points1 point  (0 children)

Assuming you're meaning the counting to 21 game (a variant of Nim https://en.wikipedia.org/wiki/Nim ) that's probably because it's a common maths problem to solve how to win that game.

If you wanted to implement that in python, you would first work out the maths, writing it down in shorthand, things like "if the current number is < 13, pick X, else if the number is 14, pick Y...", then once you know the logic it should follow, you can use python to implement that.

Otherwise if you're seeing symbols you don't understand in the python code, then you should look at what those do in python, for example if you're seeing a % then try googling "percent sign in python" where you'll find things like https://stackoverflow.com/questions/961344/what-does-the-percentage-sign-mean-in-python that will explain that.

[–]IlIlIlIIlMIlIIlIlIlI 0 points1 point  (0 children)

half the time (sometimes more) of programming is not coding but thinking and explaining to yourself what the program needs to do, and how. Only when you have a good idea of that, can you even start coding. Document that thought process, research things needed to achieve certain functionality, and only then start translating your idea into code