Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit dbf9e46

Browse files
Merge pull request #664 from mmakrin/patch-1
Update guess_number.py
2 parents 435cd4c + 13cecef commit dbf9e46

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

projects/Guess Number/guess_number.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
larger_number = 10
66
upper_limit = 10
77
lower_limit = 1
8+
num_of_guesses=0
89

910

1011
# function to prompt user for input. will continue to ask user for proper int if invalid num passed
@@ -35,13 +36,16 @@ def guess(num, user_guess):
3536
print(f"\nNumber is higher than {user_guess}")
3637
lower_limit = user_guess
3738
user_guess = enter_and_verification(lower_limit + 1, upper_limit)
39+
num_of_guesses++
3840
elif num < user_guess:
3941
print(f"\nNumber is lower than {user_guess}")
4042
upper_limit = user_guess
4143
user_guess = enter_and_verification(lower_limit, upper_limit - 1)
44+
num_of_guesses++
4245
else:
4346
print()
4447
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")
4549

4650

4751
# while loop to prompt user to play intially, then continue to play or not

0 commit comments

Comments
 (0)