File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 1
1
import random
2
2
3
+
3
4
def guess_the_number ():
4
5
print ("Welcome to Guess the Number Game!" )
5
6
print ("I'm thinking of a number between 1 and 100." )
6
-
7
+
7
8
secret_number = random .randint (1 , 100 )
8
9
attempts = 0
9
-
10
+
10
11
while True :
11
12
try :
12
13
guess = int (input ("Enter your guess: " ))
13
14
attempts += 1
14
-
15
+
15
16
if guess == secret_number :
16
- print (f"Congratulations! You guessed the number in { attempts } attempts." )
17
+ print (
18
+ f"Congratulations! You guessed the number in { attempts } attempts." )
17
19
break
18
20
elif guess < secret_number :
19
21
print ("Too low! Try again." )
@@ -22,5 +24,6 @@ def guess_the_number():
22
24
except ValueError :
23
25
print ("Invalid input. Please enter a valid number." )
24
26
27
+
25
28
if __name__ == "__main__" :
26
29
guess_the_number ()
You can’t perform that action at this time.
0 commit comments