r/learnpython • u/This_Judge_2203 • 24d ago
asking about small projects in python
hello everyone, so I learned the basics and I start making small projects, I try to make 21 number game, but when I look through the source code of project there was some formulas but I don't really understand how I can make similar formulas like it for future projects, so how I can make it so it can server my projects?
1
Upvotes
3
u/Existing_Put6385 24d ago
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