-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
25 lines (20 loc) · 756 Bytes
/
game.py
File metadata and controls
25 lines (20 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import random
def guessing_game():
print("Welcome to the Guessing Game!")
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
attempts = 0
while True:
# Get the player's guess
guess = int(input("Enter your guess (between 1 and 100): "))
attempts += 1
# Check if the guess is correct
if guess == secret_number:
print(f"Congratulations! You guessed the correct number {secret_number} in {attempts} attempts.")
break
elif guess < secret_number:
print("Too low! Try again.")
else:
print("Too high! Try again.")
if __name__ == "__main__":
guessing_game()