/
dashytka
/
Number-Guessing-Game
Обзор
Документация
Войти
/
dashytka
/
Number-Guessing-Game
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
python
56 строк
2 KB
dashytka
create python
15 ноя 2025, 23:11
15 ноя 2025, 23:11
e2f3439
Код
Авторство
О чём код?
# Number Guessing Game import random class NumberGuesser: def __init__(self): self.score = 0 self.max_attempts = 7 self.min_number = 1 self.max_number = 100 def start_game(self): print("🎯 Welcome to the Number Guessing Game!") print(f"🤔 I'm thinking of a number between {self.min_number} and {self.max_number}") print(f"💡 You have {self.max_attempts} attempts to guess it!") secret_number = random.randint(self.min_number, self.max_number) attempts = 0 while attempts < self.max_attempts: attempts += 1 remaining_attempts = self.max_attempts - attempts try: guess = int(input(f"\n🔢 Attempt {attempts}/{self.max_attempts}. Enter your guess: ")) except ValueError: print("❌ Please enter a valid number!") attempts -= 1 continue if guess == secret_number: print(f"🎉 Congratulations! You guessed the number {secret_number} in {attempts} attempts!") self.score += (self.max_attempts - attempts + 1) * 10 break elif guess < secret_number: print(f"📈 Too low! {remaining_attempts} attempts remaining.") else: print(f"📉 Too high! {remaining_attempts} attempts remaining.") if remaining_attempts == 0: print(f"💀 Game Over! The number was {secret_number}") print(f"🏆 Your current score: {self.score}") return self.play_again() def play_again(self): play_again = input("\n🔄 Would you like to play again? (y/n): ").lower() if play_again in ['y', 'yes']: return self.start_game() else: print(f"👋 Thanks for playing! Final score: {self.score}") return False # Start the game if __name__ == "__main__": game = NumberGuesser() game.start_game()