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 11import random
22
3+
34def guess_the_number ():
45 print ("Welcome to Guess the Number Game!" )
56 print ("I'm thinking of a number between 1 and 100." )
6-
7+
78 secret_number = random .randint (1 , 100 )
89 attempts = 0
9-
10+
1011 while True :
1112 try :
1213 guess = int (input ("Enter your guess: " ))
1314 attempts += 1
14-
15+
1516 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." )
1719 break
1820 elif guess < secret_number :
1921 print ("Too low! Try again." )
@@ -22,5 +24,6 @@ def guess_the_number():
2224 except ValueError :
2325 print ("Invalid input. Please enter a valid number." )
2426
27+
2528if __name__ == "__main__" :
2629 guess_the_number ()
You can’t perform that action at this time.
0 commit comments