GUESS THE NUMBER
ABSTRACT
The "Guess the Number" game is a simple yet engaging mini project developed to demonstrate
fundamental programming concepts in an interactive way. In this project, the computer automatically
generates a random number within a specified range, typically between 1 and 100, and the user is
required to guess the number through repeated attempts. After each guess, the system provides feedback
indicating whether the entered number is too high or too low compared to the actual number. This
process continues until the user successfully identifies the correct number. The main objective of this
project is to create an interactive environment where users can enjoy the game while also understanding
the logic behind it.
This project plays an important role in strengthening the basic concepts of programming such as loops,
conditional statements, user input handling, and random number generation. It also helps in developing
problem-solving skills and logical thinking ability. By continuously interacting with the system and
analyzing the feedback, users learn how to approach a problem step by step and refine their guesses
accordingly. The simplicity of the game makes it suitable for beginners who are new to programming
and want to build a strong foundation.
In addition, the project can be easily modified and enhanced with advanced features such as limiting the
number of attempts, introducing multiple difficulty levels, maintaining a score system, or even
converting it into a graphical user interface. These enhancements can make the application more user-
friendly and visually appealing. The program is efficient, reusable, and requires minimal system
resources, making it suitable for implementation on basic computing devices. Overall, the "Guess the
Number" mini project serves as an excellent example of how simple logic can be transformed into an
interactive application.
INTRODUCTION
In the modern era, computer-based applications and games have become an essential part of learning
and entertainment. Simple games, in particular, play a significant role in helping beginners understand
the fundamentals of programming in an engaging and interactive way. One such basic and widely used
beginner-level program is the "Guess the Number" game. This project is designed to demonstrate how a
computer can interact with a user by generating a random number and guiding the user to arrive at the
correct answer through logical hints.
The "Guess the Number" game is based on a simple concept. The system randomly selects a number
within a predefined range, typically between 1 and 100, and the user is required to guess this number.
After each guess, the program provides feedback indicating whether the guessed number is higher or
lower than the actual number. This process continues until the user successfully identifies the correct
number. The main objective of the game is not only to entertain but also to improve the user's logical
thinking and decision-making abilities.
From a programming perspective, this project is highly useful for beginners as it introduces several
important concepts. These include the use of random number generation, conditional statements (if-
else), loops, and user input handling. By implementing this game, students can understand how
programs make decisions based on input and how repetition is controlled using loops. It also helps in
learning how to track attempts and provide meaningful output to users.
Moreover, the project highlights the importance of user interaction in software applications. The
continuous feedback mechanism, such as "Too High" or "Too Low," enhances the user experience and
keeps the user engaged throughout the process. This type of interaction is commonly used in many real-
world applications, making this project a foundational step toward more advanced software
development.
In addition, the "Guess the Number" game can be easily modified and extended with additional features
such as difficulty levels, limited attempts, scoring systems, and graphical interfaces. These
enhancements can further improve the complexity and usability of the program. Therefore, this project
serves as a strong base for understanding both basic and intermediate programming concepts.
EXISTING SYSTEM AND DISADVANTAGES
Existing System
The existing system for the "Guess the Number" game is based on a traditional, manual method where
one person thinks of a number within a specific range, and another person attempts to guess it. This type
of system does not involve any computer or automation. The person who thinks of the number provides
feedback to the guesser by indicating whether the guessed number is higher, lower, or correct.
In this manual approach, the interaction depends entirely on human participation. The number selection
is done mentally, and responses are given verbally. There is no predefined structure or system to manage
the flow of the game. Each round of the game depends on the honesty and consistency of the person
providing feedback. The game continues until the correct number is guessed, without any formal
tracking mechanism.
Additionally, the traditional system does not store any data related to the game such as the number of
attempts, time taken, or previous guesses. It is a temporary activity that resets every time a new game
starts. There is also no validation to ensure that the guessed number falls within the defined range. This
makes the system less reliable and inconsistent.
Disadvantages
The existing manual system has several limitations which reduce its effectiveness and reliability:
1. Lack of Automation – The entire process depends on human effort, making it slow and
inefficient.
2. No Accuracy Guarantee – There is no mechanism to ensure the feedback provided is accurate or
honest.
3. No Record Maintenance – The system does not store any game data such as attempts, time, or
scores.
4. Time-Consuming Process – Without automation, each game session takes longer and is less
efficient.
5. Limited User Engagement – The absence of interactive feedback reduces player motivation and
interest.
PROPOSED SYSTEM AND ADVANTAGES
Proposed System
The proposed system is a computer-based interactive game called "Guess the Number", designed to
provide an engaging and user-friendly experience. In this system, the computer automatically generates
a random number within a specified range (for example, 1 to 100). The user is then prompted to guess
the number through continuous input.
The system processes each guess by comparing it with the generated number and provides immediate
feedback such as "Too High", "Too Low", or "Correct Guess". This feedback helps the user adjust their
guesses logically and reach the correct answer in fewer attempts. The program continues running in a
loop until the correct number is guessed.
Additionally, the system keeps track of the number of attempts made by the user. Once the correct
number is guessed, the system displays a success message along with the total attempts taken. This
feature encourages users to improve their performance by minimizing the number of guesses.
The proposed system is simple, efficient, and suitable for beginners to understand fundamental
programming concepts such as loops, conditional statements, and random number generation. It can be
implemented using programming languages like Python, C, or Java, making it versatile and easy to
develop.
Advantages
The proposed system offers several advantages over traditional manual guessing games:
• Automation – The number is generated automatically, removing the need for human
participation.
• Instant Feedback – The system immediately responds with "Too High" or "Too Low" after every
guess.
• Improved User Engagement – Interactive prompts and messages keep the user motivated
throughout.
• Accuracy and Reliability – The computer ensures consistent and honest feedback every time.
• Tracks Performance – The system counts the number of attempts and displays them at the end.
ARCHITECTURAL DIAGRAM
The Architectural Diagram of the "Guess the Number" game illustrates the flow of the system from start
to finish. It shows how different components interact with each other to provide a complete gaming
experience.
[ ARCHITECTURAL DIAGRAM OF GUESS THE NUMBER GAME ]
ARCHITECTURAL DIAGRAM
MODULES
The "Guess the Number" project is divided into several functional modules to ensure clarity, simplicity,
and efficient execution. Each module is responsible for a specific task in the system. The modules used
are:
• Random Number Generator Module
• User Input Module
• Validation and Comparison Module
• Hint Display Module
• Game Controller Module
1. Random Number Generator Module
This module is responsible for generating a random number within a predefined range (for example, 1 to
100). It uses built-in programming functions to ensure that the number is unpredictable each time the
program runs. This randomness makes the game challenging and engaging for the user. The module
initializes at the beginning of the program and stores the generated number securely so that it can be
compared with user inputs later.
2. User Input Module
The user input module handles all interactions between the user and the system. It prompts the user to
enter their guessed number and ensures that the input is received correctly. This module may also
include basic validation to check whether the entered value is numeric and within the allowed range. If
invalid input is provided, the system can ask the user to re-enter the value, ensuring smooth gameplay
without errors.
3. Validation and Comparison Module
This module compares the user's guess with the randomly generated number. It plays a crucial role in
determining whether the guess is correct, too high, or too low. Based on the comparison, the module
sends appropriate signals to the output module. This logical decision-making process is the core
functionality of the game and ensures that the program behaves correctly.
CODING
import random
import sys
LOWER_BOUND = 1
UPPER_BOUND = 100
MAX_ATTEMPTS = 10
def generate_secret_number(low=LOWER_BOUND, high=UPPER_BOUND):
"""
Generate and return a random integer between
low and high (both inclusive).
"""
secret = [Link](low, high)
return secret
def get_valid_guess(low=LOWER_BOUND, high=UPPER_BOUND):
while True:
try:
user_input = input(
f" Enter your guess ({low} - {high}): "
)
guess = int(user_input) # Convert to integer
# Range check
if guess < low or guess > high:
print(f" [!] Please enter a number between "
f"{low} and {high}.\n")
continue # Ask again
return guess # Valid - return it
except ValueError:
# Non-integer was entered (e.g. 'abc', '3.5')
print(" [!] Invalid input. Please enter a "
"whole number.\n")
# Loop continues - asks user again
def check_guess(guess, secret):
"""
Compare the user's guess to the secret number.
Parameters:
guess (int): The number entered by the user.
secret (int): The randomly generated secret number.
Returns:
str: 'low' - guess is less than secret
'high' - guess is greater than secret
'correct' - guess equals secret
"""
if guess < secret:
return "low"
elif guess > secret:
return "high"
else:
return "correct"
def display_hint(result):
"""
Print a descriptive hint to guide the user's next guess.
Parameters:
result (str): One of 'low', 'high', or 'correct'.
"""
if result == "low":
print(" Too Low! Try a higher number.\n")
elif result == "high":
print(" Too High! Try a lower number.\n")
elif result == "correct":
print(" Correct! Well done!\n")
else:
# Defensive: handle unexpected result codes
print(" [!] Unknown result code received.\n")
def play_round(secret, low=LOWER_BOUND, high=UPPER_BOUND):
"""
Run a single round of the Guess the Number Game.
The loop continues until the user correctly guesses the
secret number. After each wrong guess, a hint is shown.
Parameters:
secret (int): The secret number to be guessed.
low (int): Lower bound (for the input prompt).
high (int): Upper bound (for the input prompt).
Returns:
int: Total number of attempts taken to win.
"""
attempts = 0 # Initialise counter
while True: # Keep looping until correct
guess = get_valid_guess(low, high) # Validated input
attempts += 1 # Increment attempt counter
result = check_guess(guess, secret) # Compare values
display_hint(result) # Show hint to user
if result == "correct":
# User guessed the number - exit the loop
print(f" You guessed it in {attempts} attempt(s)!\n")
return attempts # Return count to caller
# Remaining attempts warning (optional feature)
remaining = MAX_ATTEMPTS - attempts
if remaining > 0 and result != "correct":
print(f" Attempts used: {attempts} | Remaining: {remaining}\n")
elif remaining <= 0:
print(f" No attempts left! The number was {secret}.\n")
return attempts # Exit even on failure
def play_game():
"""
Top-level controller for the Guess the Number Game.
Displays the welcome banner, starts a round, then manages
the replay loop until the user chooses to exit.
"""
print("=" * 47)
print(" Welcome to the Guess the Number Game!")
print("=" * 47)
print(f" Guess the number between {LOWER_BOUND} and {UPPER_BOUND}.\n")
secret = generate_secret_number()
attempts = play_round(secret)
print(f" The secret number was : {secret}")
print(f" Total attempts taken : {attempts}\n")
while True:
choice = input(
" Do you want to play again? (yes / no): "
).strip().lower()
if choice == "yes":
print()
play_game() # Restart the game
return # Prevent stacked calls
elif choice == "no":
print("\n Thank you for playing! Goodbye. :-)")
print("=" * 47)
[Link](0) # Clean exit
else:
print(" [!] Please type 'yes' or 'no'.\n")
if __name__ == "__main__":
play_game()
SCREENSHOT
CONCLUSION
The "Guess the Number" mini project successfully demonstrates the fundamental concepts of
programming in a simple, interactive, and engaging manner. This project was designed to help
understand how a computer program can interact with a user, process inputs, and provide meaningful
outputs based on logical conditions. By implementing this game, we explored key programming
elements such as loops, conditional statements, variables, and random number generation, which form
the foundation of most software applications.
One of the major outcomes of this project is the improvement in logical thinking and problem-solving
ability. The game requires continuous comparison between the user's input and the system-generated
number, which helps in understanding how decision-making works in programming. The use of
feedback such as "Too High" or "Too Low" enhances user interaction and makes the program more
dynamic and user-friendly. It also demonstrates how programs can guide users step by step toward
achieving a goal.
Additionally, the project highlights the importance of user experience in software development. Even
though the logic behind the game is simple, the way the program communicates with the user plays a
crucial role in making it engaging. This shows that even small applications can be designed in a way that
they are both functional and enjoyable to use.
Another important aspect learned through this project is code structure and organization. Dividing the
program into logical sections such as input handling, processing, and output display makes the code
easier to understand, debug, and maintain. This practice is essential when developing larger and more
complex systems.
In conclusion, the "Guess the Number" game is an excellent beginner-level project that effectively
combines learning with creativity. It not only strengthens programming basics but also encourages
experimentation and further development. With additional features such as difficulty levels, graphical
interfaces, and scoring systems, this simple project can be enhanced into a more advanced application.
Overall, this project serves as a strong foundation for understanding more complex programming
concepts and real-world software development.
FUTURE ENHANCEMENT
The "Guess the Number" game can be further improved by adding several advanced features to enhance
user experience, increase difficulty levels, and introduce modern programming concepts. These
enhancements will make the project more interactive, efficient, and suitable for real-world applications.
One of the major improvements is the introduction of difficulty levels such as Easy, Medium, and Hard.
In Easy mode, the number range can be limited from 1 to 50, while Medium can range from 1 to 100,
and Hard can go up to 1 to 500 or more. This allows users to choose their comfort level and makes the
game more engaging for different types of players.
Another important feature is limiting the number of attempts. Instead of allowing unlimited guesses, the
system can restrict the number of tries based on difficulty level. This adds challenge and encourages
strategic thinking. Along with this, a scoring system can be implemented where users earn points based
on how quickly they guess the correct number. Fewer attempts will result in higher scores.
The project can also be enhanced by developing a Graphical User Interface (GUI) using tools like
Tkinter in Python. A GUI will make the game visually appealing with buttons, text boxes, and
interactive messages instead of simple console output. This will improve usability and make the
application more professional.
Another enhancement is the addition of multiplayer mode, where two or more users can compete to
guess the number. The system can track each player's attempts and declare a winner based on
performance. This introduces competitive gameplay and increases user engagement.
The system can also include a hint system where additional clues are provided, such as whether the
number is even or odd, divisible by certain numbers, or within a smaller range. This makes the game
more dynamic and less repetitive.
REFERENCES
6. Python Software Foundation. Python Documentation. Available at: [Link]
This official documentation provides detailed information about Python programming, including
syntax, libraries, and functions such as random number generation used in this project.
7. W3Schools. Python Tutorial. Available at: [Link] A beginner-
friendly resource that explains Python concepts like loops, conditional statements, and user input
handling which are essential for developing this game.
8. GeeksforGeeks. Python Programming Language. Available at:
[Link] This platform offers
explanations and examples on random functions, control statements, and logic building
techniques applied in the project.
9. Tutorialspoint. Python Basics. Available at: [Link]
Provides structured learning materials on Python fundamentals including decision-making
statements and iteration which are used in this application.
10. Downey, Allen B. Think Python: How to Think Like a Computer Scientist. A book that
introduces programming concepts and logical thinking approaches helpful for understanding how
the guessing game works.
11. Zelle, John. Python Programming: An Introduction to Computer Science. This book explains
core programming ideas such as loops, conditionals, and user interaction in simple terms.
12. Classroom Notes and Study Materials provided by the faculty. These materials helped in
understanding the fundamental programming structure and logic implementation.