0% found this document useful (0 votes)
4 views

Python Case Study-1

The document outlines a case study on a Number Guessing Game developed in Python, detailing its abstract, introduction, software requirements, methodology, results, conclusion, and future scope. The game engages users by allowing them to guess a randomly generated number while providing feedback on their guesses, thus enhancing problem-solving skills and logical thinking. Future enhancements include adding a graphical interface, score tracking, and various game modes to improve user experience and educational value.

Uploaded by

vmadabat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Case Study-1

The document outlines a case study on a Number Guessing Game developed in Python, detailing its abstract, introduction, software requirements, methodology, results, conclusion, and future scope. The game engages users by allowing them to guess a randomly generated number while providing feedback on their guesses, thus enhancing problem-solving skills and logical thinking. Future enhancements include adding a graphical interface, score tracking, and various game modes to improve user experience and educational value.

Uploaded by

vmadabat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

PYTHON CASE

STUDY

NUMBER GUESSING
GAME
INDEX:
●​ABSTRACT
●​INTRODUCTION
●​SRS(SOFTWARE REQUIREMENT
SPECIFICATIONS)
1.​ Functional Requirements
2.​ Non-Functional Requirements
●​ METHODOLOGY
●​RESULTS
●​CONCLUSION
●​FUTURE SCOPE
ABSTRACT:
The number guessing game is a fun and interactive
way to apply basic programming concepts such as
loops, conditionals, user input, and random number
generation. It challenges players to use logic and
strategy to guess the correct number within a set
range. Through this project, we demonstrated how
even a simple game can help build a strong
foundation in coding, improve problem-solving skills,
and provide an engaging user experience. This
game can also be further enhanced with features
like difficulty levels, limited attempts, hints, and score
tracking.
INTRODUCTION:
A Number Guessing Game will generate a random
number within a specified range, allow the user to
input guesses, provide feedback on whether the
guess is too high or too low or too close(If the
number guessed is close to the computer generated
number by three units to the left or right a "too close"
statement is surfaced), track the number of
attempts(The hard level has 10 attempts while the
easy level has 5 attempts) and determine the end
game conditions when the user guesses correctly or
runs out of attempts. The game should also display
guess again and congratulatory messages, and
potentially offer different difficulty levels with varying
numbers of attempts.
It is a classic and exciting game of logic, intuition,
and a little bit of luck! This game is simple yet
engaging, making it perfect for players of all ages.
The concept is straightforward: the computer
randomly selects a secret number within a
predefined range (for example, between 1 and
100), and your task is to figure out what that
number is through a series of guesses.

Each time you make a guess, the computer will


give you a hint – either “too high” or “too low” –
helping you narrow down the possibilities. Using
these clues, you must adjust your next guess
accordingly, aiming to find the correct number in
as few attempts as possible. It’s a fun way to test
your decision-making skills and learn how to use
logic and strategy to reach a goal.

The Number Guessing Game is not only


entertaining but also educational. It encourages
critical thinking, pattern recognition, and
problem-solving, making it a great activity for both
children and adults. You can play it alone for
personal improvement, or challenge your friends
and family to see who can guess the number the
fastest.There are also different variations of the
game to increase the difficulty, such as limiting the
number of guesses, increasing the range of
possible numbers, or adding a time limit. These
changes make the game even more challenging
and exciting!

Whether you’re looking for a quick mental


workout, a fun break from your routine, or a way
to sharpen your thinking skills, the Number
Guessing Game is the perfect choice. So, are you
ready to put your guessing skills to the test? Dive
in, start guessing, and see how quickly you can
uncover the mystery number!

SRS
Here's a more detailed breakdown of the software
requirements:
Functional Requirements:
●​Random Number Generation
●​The software must be able to generate a
random number within a specified range (e.g.,
1-100).
●​User Input:
The software should allow the user to input their
guess, which can be done through a
command-line interface (CLI) or a graphical user
interface (GUI).
●​Guess Validation:
The software should validate the user's input to
ensure it's a valid number within the acceptable
range.
●​Feedback:
The software should provide feedback to the
user after each guess, indicating whether the
guess is too high or too low.
●​Attempt Tracking:
The software should keep track of the number of
attempts the user has made.
●​End Game Conditions:
The game should end when the user guesses
the correct number or runs out of attempts.
●​Win Condition:
The software should display a congratulatory
message when the user guesses the correct
number, including the number of attempts it
took.
●​Loss Condition:
The software should display a message when
the user runs out of attempts.
●​Optional Features:
Difficulty Levels: The game could offer different
difficulty levels that adjust the range of numbers
or the number of attempts allowed.
●​Multiple Rounds: The game could allow the user
to play multiple rounds.
●​High Score Tracking: The game could track and
display high scores.
Non-Functional Requirements:
●​User-Friendliness:
The game should be easy to use and
understand, with clear instructions and
feedback.
●​Performance:
The game should be responsive and not take
too long to execute, especially for generating
random numbers and processing user input.
●​Error Handling:
The software should handle invalid input or
unexpected errors gracefully, such as by
displaying error messages.
●​Maintainability:
The code should be well-structured and
documented, making it easy to maintain and
modify in the future.
●​Security:
If the game involves user accounts or other
sensitive information, it should be designed to
be secure against unauthorized access.

CODE

import random

EASY_LEVEL_ATTEMPTS = 10
HARD_LEVEL_ATTEMPTS = 5
def set_difficulty(level_chosen):
if level_chosen == "easy":
return EASY_LEVEL_ATTEMPTS
elif level_chosen == "hard":
return HARD_LEVEL_ATTEMPTS
else:
print("Invalid difficulty. Defaulting to easy.")
return EASY_LEVEL_ATTEMPTS

def check_answer(guessed_number, answer, attempts):


if guessed_number < answer:
if (answer - guessed_number) < 3:
print("Your guess is too close.")
else:
print("Your guess is too low.")
elif guessed_number > answer:
if (guessed_number - answer) < 3:
print("Your guess is too close.")
else:
print("Your guess is too high.")

🎉
else:
print(f" Congrats! You guessed it right. The answer was {answer}.")
return "correct"
return attempts - 1

def game():
print("I'm thinking of a number between 1 and 50.")
answer = random.randint(1, 50)
level = input("Choose your difficulty (easy or hard): ").lower()
attempts = set_difficulty(level)

guessed_number = None
while attempts > 0:
print(f"\nYou have {attempts} attempts remaining.")
try:
guessed_number = int(input("Make a guess: "))
if guessed_number < 1 or guessed_number > 50:
print("Please guess a number between 1 and 50.")
continue
except ValueError:
print("Invalid input. Please enter a number.")
continue

result = check_answer(guessed_number, answer, attempts)


if result == "correct":
break
else:
attempts = result
😞
if attempts == 0:
print(f"\n You're out of guesses. The correct number was
{answer}.")
else:
print("Guess again.")

game()

FUTURE SCOPE:

Future Scope for Number Guessing Game in Python


GUI with Tkinter or PyQt

Convert your text-based game into a graphical one using Tkinter (built-in)
or PyQt for a more professional look.

Smart Computer Player (AI Mode)

Let the computer guess your number using binary search or a simple AI
algorithm.

Teach players how efficient search strategies work.

Add Score Tracking

Store player guesses, time taken, and high scores in a local file (like JSON
or CSV).
Optionally use SQLite for a small database to keep track of scores.

Unit Testing with unit test or pytest

Make your code cleaner and more robust by writing tests for the core logic.

📊 Data Visualization (Optional)


Use matplotlib to create charts showing player performance over time (e.g.,
guesses per round).

Multiple Game Modes

Add difficulty levels: Easy (1–10), Medium (1–100), Hard (1–1000).

Add a "limited guesses" mode or a "timed" mode.

Flask/Django Web Version

Build a web version of your game using Flask or Django.

Can include login, leaderboard, and online play features.

Save User Profiles

Store usernames, scores, and settings using a simple database (SQLite +


SQLAlchemy or just JSON files).

Colorful CLI with colorama or rich

Enhance your terminal game by using colorama or rich for text colors,
animations, and better visuals.

Convert to Android App with Kivy


Use Kivy, a Python framework, to make your game run on mobile devices.

Educational Version

Add a "learn mode" that gives hints and explains logic to younger users.

Package & Share on PyPI

Package your game as a Python module and upload it to PyPI so others


can pip install it.

RESULT:
EASY LEVEL:
HARD LEVEL:
INVALID INPUT:
It will default to EASY level
CONCLUSION:
In conclusion, the number guessing game is a
simple yet engaging way to demonstrate
fundamental programming concepts such as
conditionals, loops, user input, and random number
generation. It challenges the player’s logic and
decision-making while also offering an interactive
experience. Through this project, we not only
created a fun game but also strengthened our
understanding of core coding principles and how
they work together to build interactive applications.
Team Members:

Vidya (2024025667)
Anjana (2024014012)
Chavi Soni (2024003598)
Harini (2024000833)

You might also like