We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1adbbcb commit 7766484Copy full SHA for 7766484
1 file changed
Guess the Number Game/guess-the-number.py
@@ -0,0 +1,17 @@
1
+import random
2
+
3
+def guess_the_number():
4
+ number = random.randint(1, 100)
5
+ attempts = 0
6
+ while True:
7
+ guess = int(input("Guess the number (between 1 and 100): "))
8
+ attempts += 1
9
+ if guess < number:
10
+ print("Too low! Try again.")
11
+ elif guess > number:
12
+ print("Too high! Try again.")
13
+ else:
14
+ print(f"Congratulations! You guessed the number in {attempts} attempts.")
15
+ break
16
17
+guess_the_number()
0 commit comments