Skip to content

ScriptSynapse/Number-Guessing-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Number Guessing Game ๐Ÿ”ข

A classic command-line number guessing game built with Python. This project is a great starting point for beginners to learn fundamental programming concepts.


๐Ÿ“œ Description

This is a simple interactive game where the computer thinks of a random integer within a specified range (e.g., 1 to 100), and the player's objective is to guess that number. The program provides feedback after each guess, telling the player if their guess was "Too high!" or "Too low!". The game ends when the player correctly guesses the number or runs out of attempts.


โœจ Features

  • Random Number Generation: A secret number is randomly generated at the start of each game.
  • User Input: Prompts the user to enter their guess.
  • Feedback System: Informs the user if their guess is too high or too low.
  • Guess Limiter: The player has a limited number of attempts to guess the number, adding a layer of challenge.
  • Input Validation: Gracefully handles non-numeric input to prevent crashes.
  • Win/Loss Conditions: Displays a success message upon a correct guess or a "game over" message if the player runs out of attempts.

๐Ÿš€ How to Play

To run this game on your local machine, you'll need to have Python installed.

  1. Clone the repository (or just download the guessing_game.py file):

    git clone https://github.com/your-username/your-repository-name.git
  2. Navigate to the project directory:

    cd your-repository-name
  3. Run the Python script from your terminal:

    python guessing_game.py
  4. Follow the on-screen instructions to play the game!


๐Ÿ› ๏ธ Code Overview

The game logic is contained within a single Python script, guessing_game.py.

  • import random: This module is used to generate the secret number.
  • while loop: The core of the game is a while loop that continues as long as the player has guesses remaining.
  • input() function: This function captures the player's guess from the terminal.
  • if-elif-else statements: These are used to compare the player's guess to the secret number and provide the appropriate feedback.
  • try-except block: This is used for error handling, specifically to catch ValueError if the user enters text that cannot be converted to an integer.

๐Ÿ”ฎ Future Enhancements

This project can be expanded with more features. Here are a few ideas:

  • Difficulty Levels: Implement 'Easy', 'Medium', and 'Hard' modes that adjust the number range and the number of allowed guesses.
  • High Score: Add a feature to save and display the best score (fewest guesses).
  • Play Again: Ask the user if they want to play another round after a game ends.
  • GUI Implementation: Rebuild the game with a graphical user interface using a library like Tkinter or PyQt.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages