r/PythonLearning • u/RegularBother614 • 5d 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?
159
Upvotes


•
u/Sea-Ad7805 5d ago
Run program above by clicking Memory Graph Web Debugger and see its state change step by step.
5
u/Dracunculous 5d 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.
2
u/ProgramBrave718 5d 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.
4
u/SoloEnder 5d ago edited 5d 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/TemperatureProper275 5d 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!
12
u/PureWasian 5d 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.2
u/RegularBother614 5d ago
The 'def' keyword low-key the most versatile and most useful keyword in python 👀👀
2
u/One_Smoke6858 5d ago
That is quite nice, like that you used try catch here.
So good job
5
u/ChaoticHippo 5d 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!
1
u/aroberge 4d ago
I think that you need to learn to post code on reddit (simply indent your code by an extra 4 spaces and copy-paste here) rather than posting images.
I can't read code in images.
1
u/Sweaty-Yogurt7305 4d ago
Hmm
1
u/hellofr4552 3d ago
Well it can be improved
1
u/shingomada012 1d ago
oh very nice program. I'm also studying Python Programming on Udemy and the vaste YT. Bro Code have a good teaching skills.
one question: which app are u using on? (on that print screen) (seems a androidOS, am I right?)