Skip to content

Commit

Permalink
Merge pull request #674 from mmakrin/patch-2
Browse files Browse the repository at this point in the history
Update guess_number.py
  • Loading branch information
Mrinank-Bhowmick authored Jan 5, 2024
2 parents f2a6725 + 7656292 commit 8177079
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions projects/Guess Number/guess_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 8177079

Please sign in to comment.