File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55larger_number = 10
66upper_limit = 10
77lower_limit = 1
8- num_of_guesses = 0
98
109
1110# function to prompt user for input. will continue to ask user for proper int if invalid num passed
@@ -36,25 +35,26 @@ def guess(num, user_guess):
3635 print (f"\n Number is higher than { user_guess } " )
3736 lower_limit = user_guess
3837 user_guess = enter_and_verification (lower_limit + 1 , upper_limit )
39- num_of_guesses + +
38+ num_of_guesses = num_of_guesses + 1
4039 elif num < user_guess :
4140 print (f"\n Number is lower than { user_guess } " )
4241 upper_limit = user_guess
4342 user_guess = enter_and_verification (lower_limit , upper_limit - 1 )
44- num_of_guesses + +
43+ num_of_guesses = num_of_guesses + 1
4544 else :
4645 print ()
4746 print (f"\n Congrats! You've guessed the correct number! It was { num } .\n " )
48- print ("\n You have tried {num_of_guesses} times to find the number.\n " )
47+ print (f "\n You have tried { num_of_guesses + 1 } times to find the number.\n " )
4948
5049
5150# while loop to prompt user to play intially, then continue to play or not
5251while True :
5352 play_y_n = input ("Welcome to Number Guesser. If you'd like to play, press 'Y': " )
5453 if play_y_n .lower () == "y" :
54+ num_of_guesses = 0
5555 num = random .randint (smaller_number , larger_number )
5656 user_guess = enter_and_verification (lower_limit , upper_limit )
57- guess (num , user_guess )
57+ guess (num , user_guess , num_of_guesses )
5858 else :
5959 print ("Thanks for playing!" )
6060 break
You can’t perform that action at this time.
0 commit comments