We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c7113f commit f303b92Copy full SHA for f303b92
1 file changed
To-do List/Number Guessing Game.md
@@ -0,0 +1,29 @@
1
+import random #importing the random module
2
+
3
+def main(): #main function
4
+ print("🎲 Welcome to the Number Guessing Game!")
5
+ print("I'm thinking of a number between 1 and 100.")
6
+ print("Try to guess it in as few attempts as possible.\n")
7
8
+ # Generate a random number between 1 and 100
9
+ number_to_guess = random.randint(1, 100)
10
+ attempts = 0
11
12
+ while True:
13
+ try:
14
+ guess = int(input("Enter your guess: "))
15
+ attempts += 1
16
17
+ if guess < number_to_guess:
18
+ print("Too low! Try again.")
19
+ elif guess > number_to_guess:
20
+ print("Too high! Try again.")
21
+ else:
22
+ print(f"🎉 Correct! You guessed the number in {attempts} attempts.")
23
+ break
24
25
+ except ValueError:
26
+ print("⚠️ Please enter a valid number.")
27
28
+if __name__ == "__main__":
29
+ main()
0 commit comments