r/PythonLearning • • Sep 07 '25

Guess game

Post image

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

17 comments sorted by

View all comments

2

u/FoolsSeldom Sep 07 '25

Good start.

Some tips:

  • put a space before and after = to make it easier to read

  • as 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 option1 and option2 outside, before, the loop

  • force the user input to lowercase using .lower() after input close )

  • you can check if an input returned string contains only a valid int string using the string method, str.isdecimal, e.g. if choose.isdecimal(): - do this BEFORE attempting to convert what the user enters to an int

0

u/Minute_Journalist593 Sep 07 '25

oky sure bro will look into it