Skip to content

Commit 62f2a04

Browse files
authored
Add files via upload
adding guess the number game.
1 parent 96d9d0c commit 62f2a04

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

guess_number.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
3+
number = random.randint(1, 50) # computer picks a number
4+
chances = 5 # total chances for user
5+
6+
print("🎮 Welcome to Guess the Number!")
7+
print("Guess the number from between 1 to 50.")
8+
print(f"You have {chances} chances to guess it.\n")
9+
10+
for i in range(chances):
11+
guess = int(input(f"Chance {i+1}: Enter your guess: "))
12+
13+
if guess == number:
14+
print("🎉 Correct! You guessed it!")
15+
break
16+
elif guess < number:
17+
print("Too low! Try again.")
18+
else:
19+
print("Too high! Try again.")
20+
else:
21+
print(f"\n😢 Game Over! The number was {number}")

0 commit comments

Comments
 (0)