From 76562922266e28ad36b05c7f6fdd3649eb5b8b30 Mon Sep 17 00:00:00 2001 From: mmakrin <115393688+mmakrin@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:30:57 +0200 Subject: [PATCH] Update guess_number.py i made one more commit to count how many times it takes to find the number --- projects/Guess Number/guess_number.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/Guess Number/guess_number.py b/projects/Guess Number/guess_number.py index b1b344b6..41602f7f 100644 --- a/projects/Guess Number/guess_number.py +++ b/projects/Guess Number/guess_number.py @@ -5,7 +5,6 @@ larger_number = 10 upper_limit = 10 lower_limit = 1 -num_of_guesses=0 # 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): print(f"\nNumber is higher than {user_guess}") lower_limit = user_guess user_guess = enter_and_verification(lower_limit + 1, upper_limit) - num_of_guesses++ + num_of_guesses=num_of_guesses+1 elif num < user_guess: print(f"\nNumber is lower than {user_guess}") upper_limit = user_guess user_guess = enter_and_verification(lower_limit, upper_limit - 1) - num_of_guesses++ + num_of_guesses=num_of_guesses+1 else: print() print(f"\nCongrats! You've guessed the correct number! It was {num}.\n") - print("\nYou have tried {num_of_guesses} times to find the number.\n") + print(f"\nYou have tried {num_of_guesses+1} times to find the number.\n") # while loop to prompt user to play intially, then continue to play or not while True: play_y_n = input("Welcome to Number Guesser. If you'd like to play, press 'Y': ") if play_y_n.lower() == "y": + num_of_guesses=0 num = random.randint(smaller_number, larger_number) user_guess = enter_and_verification(lower_limit, upper_limit) - guess(num, user_guess) + guess(num, user_guess, num_of_guesses) else: print("Thanks for playing!") break