r/PythonLearning • u/Minute_Journalist593 • Sep 07 '25
Guess game
Guy's i have tried this i know it needs lot of improvement like handing exceptional error but i have applied what i have learned till date and i wanted it to make it by using def but i was getting confused so i decided to make it this way pls rate this and suggest me where do i need to improve
225
Upvotes
2
u/FoolsSeldom Sep 07 '25
Good start.
Some tips:
put a space before and after
=to make it easier to readas well as checking for a match, generate the random number before the loop and,
check if their wrong guess is higher than the actual number, and tell user if it is
check if their wrong guess is lower than the actual number, and tell user if it is
how about keeping track of the number of guesses with a counter variable?
how about limiting the number of guesses?
add a new outer loop to allow the game to be played again with a new random number
you can define
option1andoption2outside, before, the loopforce the user input to lowercase using
.lower()afterinputclose)you can check if an
inputreturned string contains only a validintstring using the string method,str.isdecimal, e.g.if choose.isdecimal():- do this BEFORE attempting to convert what the user enters to anint