Skip to content

Commit 29ca44e

Browse files
authored
Add files via upload
1 parent 1c2ddc2 commit 29ca44e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

guess_game.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
guess += 1
20+
else:
21+
print(f"Congratulations! You've guessed the number {k} correctly in {guess} attempts.")
22+
23+
guess_number()

0 commit comments

Comments
 (0)