We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bdab885 commit 496ae6cCopy full SHA for 496ae6c
guessmenumber.py
@@ -0,0 +1,23 @@
1
+import random
2
+
3
+def guess_number():
4
+ target_number = random.randint(1, 100)
5
+ attempts = 0
6
7
+ print("Welcome to the Number Guessing Game!")
8
+ print("I've selected a random number between 1 and 100. Can you guess it?")
9
10
+ while True:
11
+ guess = int(input("Enter your guess: "))
12
+ attempts += 1
13
14
+ if guess < target_number:
15
+ print("Too low! Try again.")
16
+ elif guess > target_number:
17
+ print("Too high! Try again.")
18
+ else:
19
+ print(f"Congratulations! You guessed the number {target_number} in {attempts} attempts.")
20
+ break
21
22
+if __name__ == "__main__":
23
+ guess_number()
0 commit comments