We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1c2ddc2 commit 29ca44eCopy full SHA for 29ca44e
1 file changed
guess_game.py
@@ -0,0 +1,23 @@
1
+from random import randint
2
+
3
+k = randint(1, 100)
4
5
+def guess_number():
6
+ print("Welcome to the Guessing Game!")
7
+ print("I have selected a number between 1 and 100.")
8
+ print("Try to guess it!")
9
10
+ guess = 1
11
+ x = -1
12
+ while x != k:
13
+ x = int(input(f"Enter your {guess} guess: "))
14
+ if x < k:
15
+ print("Too low! Try again.")
16
+ guess += 1
17
+ elif x > k:
18
+ print("Too high! Try again.")
19
20
+ else:
21
+ print(f"Congratulations! You've guessed the number {k} correctly in {guess} attempts.")
22
23
+guess_number()
0 commit comments