Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
36 changes: 36 additions & 0 deletions Game-Galore/guessing_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import random

def guessing_game():
print("Welcome to the Number Guessing Game!")
lower_bound = 1
upper_bound = 100
secret_number = random.randint(lower_bound, upper_bound)
attempts = 0
max_attempts = 10

print(f"I've selected a number between {lower_bound} and {upper_bound}. You have {max_attempts} attempts to guess it.")

while attempts < max_attempts:
try:
guess = int(input("Enter your guess: "))
attempts += 1

if guess < lower_bound or guess > upper_bound:
print(f"Please guess a number between {lower_bound} and {upper_bound}.")
continue

if guess < secret_number:
print("Too low!")
elif guess > secret_number:
print("Too high!")
else:
print(f"Congratulations! You've guessed the number {secret_number} in {attempts} attempts.")
break
except ValueError:
print("Invalid input. Please enter an integer.")

if attempts == max_attempts:
print(f"Sorry, you've used all your attempts. The secret number was {secret_number}.")

if __name__ == "__main__":
guessing_game()
File renamed without changes.