Skip to content

Commit 7656292

Browse files
authored
Update guess_number.py
i made one more commit to count how many times it takes to find the number
1 parent eaa9d06 commit 7656292

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

projects/Guess Number/guess_number.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
larger_number = 10
66
upper_limit = 10
77
lower_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"\nNumber 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"\nNumber 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"\nCongrats! You've guessed the correct number! It was {num}.\n")
48-
print("\nYou have tried {num_of_guesses} times to find the number.\n")
47+
print(f"\nYou 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
5251
while 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

0 commit comments

Comments
 (0)