From 650df442b954cab8f7f50f9aa2569fdc1972f8fb Mon Sep 17 00:00:00 2001
From: yesayath <msefulat@gmail.com>
Date: Fri, 17 Feb 2023 16:46:16 +0200
Subject: [PATCH] added condition to check number range and updated the print
 to f-strings

---
 guess_the_number.py | 52 ++++++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/guess_the_number.py b/guess_the_number.py
index 9fe40d0..6d9abc9 100644
--- a/guess_the_number.py
+++ b/guess_the_number.py
@@ -1,20 +1,32 @@
-import random
-number = random.randint(1, 10)
-
-player_name = input("Hello, what is your name? ")
-number_of_guesses = 0
-print('I\'m glad to meet you! {} \nLet\'s play a game with you, I will think a number between 1 and 10 then you will guess, alright? \nDon\'t forget! You have only 3 chances so guess:'.format(player_name))
-
-while number_of_guesses < 3:
-    guess = int(input())
-    number_of_guesses += 1
-    if guess < number:
-        print('Your estimate is too low, go up a little!')
-    if guess > number:
-        print('Your estimate is too high, go down a bit!')
-    if guess == number:
-        break
-if guess == number:
-    print( 'Congratulations {}, you guessed the number in {} tries!'.format(player_name, number_of_guesses))
-else:
-    print('Close but no cigar, you couldn\'t guess the number. \nWell, the number was {}.'.format(number))
+import random
+number = random.randint(1, 10)
+
+player_name = input("Hello, what is your name? ")
+
+number_of_guesses = 0
+
+print('I\'m glad to meet you! {} \nLet\'s play a game with you, I will think a number between 1 and 10 then you will guess, alright? \nDon\'t forget! You have only 5 chances so guess:'.format(player_name))
+
+while number_of_guesses < 5:
+    guess = int(input())
+    
+    number_of_guesses += 1
+    
+    if guess > 10 or guess < 1: #checking if within range
+        print(f'Number of out of range. The number must be between 1 and 10')
+        print(f'You now have {5 - number_of_guesses} chances left')
+    elif guess < number: #checking if less than the correct number
+        print(f'Your estimate is too low, go up a little!')
+        print(f'You now have {5 - number_of_guesses} chances left')
+    elif guess > number: #checking if higher than the correct number
+        print(f'Your estimate is too high, go down a bit!')
+        print(f'You now have {5 - number_of_guesses} chances left')
+    else: # The number is correct
+        print(f'Congratulations {player_name}, you guessed the number in {number_of_guesses} tries!')
+        break
+    if number_of_guesses == 5:
+        break
+    else:
+        continue
+
+print(f'Close but no cigar, you couldn\'t guess the number. \nWell, the number was {number}')