Skip to content

Commit 1046afa

Browse files
committed
guess the number game added
1 parent b22024d commit 1046afa

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

guess_the_number_game.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
print("Welcome to the guess the number game.You have Eleven attempts to guess the number between 1 and 100.")
3+
number=int(input("Enter your number:"))
4+
number_to_guess=np.random.randint(1,100)
5+
attempts=11
6+
while attempts>0:
7+
if number==number_to_guess:
8+
print("Congratulations! You guessed the number correctly.")
9+
break
10+
elif number<number_to_guess:
11+
print("Too low! Try again.")
12+
else:
13+
print("Too high! Try again.")
14+
attempts-=1
15+
if attempts>0:
16+
print(f"number of attempts left: {attempts}")
17+
number=int(input("Enter your number:"))
18+
19+
if attempts==0:
20+
print(f"Sorry, you've used all your attempts. The number was {number_to_guess}.")
21+
print("Better luck next time!, Thank you for playing the game.")

0 commit comments

Comments
 (0)