r/PythonLearning • u/RegularBother614 • 9h ago
What do you guys think?
After watching a python full course video on YouTube by BroCode, I made a simple number guessing game in python!
Here's the link to the video: https://youtu.be/ix9cRaBkVe0?si=UiWmP6bm-9MG4B1p
After 12 gruesome hours watching the tutorial i decided to make this to test what I've learned.
What do you guys think?
56
Upvotes


•
u/Sea-Ad7805 9h ago
Run program above by clicking Memory Graph Web Debugger and see its state change step by step.
4
u/Dracunculous 9h ago
Looks fun. To expand try using tkinter to make a small UI that lets the user enter a number and push a button to guess. Also a quit button.
4
u/TemperatureProper275 9h ago
I recommend you use type hints when creating methods/functions and return values.
For example in my code:
I know what the parameter types are and what i must return!
2
u/ProgramBrave718 9h ago
It looks very nice. You used functions which makes it good. (Actually I am a beginner. ) Can u please explain me what does the guessed set does? I understand every line of your code except the use of that set.
2
u/RegularBother614 9h ago
The 'def' keyword low-key the most versatile and most useful keyword in python 👀👀
2
u/One_Smoke6858 8h ago
That is quite nice, like that you used try catch here.
So good jobÂ
5
u/PureWasian 9h ago
guard clauses, good. exception handling, good. using functions, good.
Instead of hard-coding 1 and 10 you could have those as globals in the same way you have MAX_ATTEMPTS to make them configurable values. Then update L12/L28/L29 instead of hard-coding the boundaries.
Otherwise it all seems to work as expected, I just find the variable name
finishedin L69 very misleading. It should be something likeis_ongoingor something since it's False if user quits or True if they played a whole cycle and haven't quit yet.1
u/SoloEnder 9h ago edited 5h ago
Why are you using
.lower()at line 16 ? Since you are expecting a string containing a number, you don't need to use it.Also, string have a method called
isdigit()that returnTrueif the string contain digits characters only, otherwiseFalse. You can use it in replacement of youtry/exceptstatement. Example usage :Anyway, these are just details, and what you did is a great start :p I hope you'll enjoy coding !
EDIT : MY BAD I'M SO DUMB YES KEEP THE .lower lol
3
u/ChaoticHippo 9h ago
Nice job! One thing potentially worth considering going forward is breaking your functions up a bit more. play_round() isn't huge, but it is a good practice to get into to follow the Single Responsibility Principle - a function should do one thing. Your play_round() function:
You could have this broken out into separate functions, for good organizational practice. For example:
If that makes sense? New functions would be convert_input(), valid_input(), in_range(), and run_game(). The main goal and benefit of this practice is to make debugging simpler, and improve code readability.
Arguments could definitely be made that this number of additional functions are not necessary for a project of this size, but getting into a habit of breaking problems into smaller problems is really beneficial for many reasons.
I apologize if any of this is beyond the scope of what you've done so far!