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

Project 1.pdf

The document outlines a project titled 'Guess the Number Game' created by Ch Bhavya Sri, detailing its objectives, implementation, and user guide. The game allows users to guess a randomly selected number within a specified range, providing feedback on whether the guess is too high or too low. It includes a step-by-step algorithm, technologies used, and example code implementations in Python, along with links to run the game online.

Uploaded by

srib2183
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Project 1.pdf

The document outlines a project titled 'Guess the Number Game' created by Ch Bhavya Sri, detailing its objectives, implementation, and user guide. The game allows users to guess a randomly selected number within a specified range, providing feedback on whether the guess is too high or too low. It includes a step-by-step algorithm, technologies used, and example code implementations in Python, along with links to run the game online.

Uploaded by

srib2183
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

TITLE PAGE

--------------------------------------------------------------------------------------------------
Project name : GUESS THE NUMBER GAME
Author : Ch Bhavya sri
Date : 14-10-2024
--------------------------------------------------------------------------------------------------
Table of contents:
1. Introduction
2. Project objectives
3. Technologies used
4. System architecture
5. Implementation
6. User guide

1. Introduction:-
>>>The number guessing game is a simple terminal based application
Task 1: This project focuses on guessing the number based on given range.
 Build a Number guessing game, in which the user selects a range.

1
 Let’s say User selected a range, i.e., from A to B, where A and B belong to
Integer.
 Some random integer will be selected by the system and the user has to
guess that integer in the minimum number of guesses
2. Project objectives:-
Explanation 1:
 If the User inputs range, let’s say from 1 to 100. And compiler randomly
selected 42 as the integer.
 And now the guessing game started, so the user entered 50 as his/her first
guess.
 The compiler shows “Try Again! You guessed too high”.
 That’s mean the random number (i.e., 42) doesn’t fall in the range from 50
to 100.
 That’s the importance of guessing half of the range. And again, the user
guesses half of 50 (Could you tell me why?). So the half of 50 is 25.
 The user enters 25 as his/her second guess. This time compiler will show,
“Try Again! You guessed too small”. That’s mean the integers less than 25
(from 1 to 25) are useless to be guessed. Now the range for user guessing is
shorter, i.e., from 25 to 50.
 Intelligently! The user guessed half of this range, so that, user guessed 37
as his/her third guess. This time again the compiler shows the output, “Try
Again! You guessed too small”.
 For the user, the guessing range is getting smaller by each guess. Now
Guessing range is 37 to 43
 For which the user guessed 43 as his/her fourth guess. This time the
compiler will show an output “Try Again! You guessed too high”.
 So, the new guessing range for users will be from 37 to 43, again for which
the user guessed the half of this range, that is, 40 as his/her fifth guess.
This time the compiler shows the output, “Try Again! You guessed too
small”. Leaving the guess even smaller such that from 41 to 43. And now
the user guessed 41 as his/her sixth guess. Which is wrong and shows
output “Try Again! You guessed too small”.
 And finally, the User Guessed the right number which is 42 as
his/her seventh guess.
2
Total Number of Guesses = 7
Explanation 2:
 If the User inputs range, let’s say from 1 to 50. And compiler
randomly selected 42 as the integer.
And now the guessing game started. So the half of 50 is 25. The user enters 25 as
his/her First guess. This time compiler will show, “Try Again! You guessed too
small”. That’s mean the integers less than 25 (from 1 to 25) are useless to be
guessed.
 Now the range for user guessing is shorter, i.e., from 25 to 50.
Intelligently! User guessed half of this range, so that, user guessed as
his/her second guess. This time again the compiler shows the output,
“Try Again! You guessed too small”.
 For the user, the guessing range is getting smaller by each guess.
Now, the guessing range for user is from 37 to 50, for which the user
guessed 43 as his/her third guess. This time the compiler will show an
output “Try Again! You guessed too high”.
 So, the new guessing range for users will be from 37 to 43, again for
which the user guessed the half of this range, that is, 40 as
his/her fourth guess. This time the compiler shows the output, “Try
Again! You guessed too small”.
 Leaving the guess even smaller such that from 41 to 43. And now the
user guessed 41 as his/her fifth guess. Which is wrong and shows
output “Try Again! You guessed too small”.
 And finally, the User Guessed the right number which is 42 as his/her
sixth guess.
Total Number of Guesses = 6

 So, the minimum number of guesses depends upon range. And the compiler
must calculate the minimum number of guessing depends upon the range,
on its own. For this, we have a formula:-
 Minimum number of guessing = log2(Upper bound – lower bound )+ 1

Step-by-step algorithm:
3
 User inputs the lower bound and upper bound of the range.
 The compiler generates a random integer between the range and store it in
a variable for future references.
 For repetitive guessing, a while loop will be initialized.
 If the user guessed a number which is greater than a randomly selected
number, the user gets an output “Try Again! You guessed too high“
 Else If the user guessed a number which is smaller than a randomly
selected number, the user gets an output “Try Again! You guessed too
small”
 And if the user guessed in a minimum number of guesses, the user gets
a “Congratulations! ” Output.
 Else if the user didn’t guess the integer in the minimum number of
guesses, he/she will get “Better Luck Next Time!” output.

3.Technologies used:-

 Programming language: Python , c , Java.


 Libraries: Random( for random number generation).

4.System architecture:- Flow chart

random number generation

user input

compare guess

5. Implementation :Below is the Implementation of the Algorithm using python

Method 1:

import random

print("Hi welcome to the game, This is a number


guessing game.\nYou got 7 chances to guess the number.
Let's start the game")
4
n= random.randrange(100)

chances = 7

counter = 0

while counter < chances:

counter += 1
my_guess = int(input('Please Enter your Guess :
'))

if my_guess == n:
print(f"The number is {n} and found
in{counter}")
break

elif counter >= chances and my_guess !=n:


print(f'sorry,The number is {n} better luck
later')

elif my_guess > n:


print('Your guess is higher ')

elif my_guess < n:


print('Your guess is lesser')
6.User guide :
 Requirements:- You need python IDE in your computer.
 In this project I used pycharm open pycharm and save the
current file and enter source code and you can run it.
OUTPUT: Below is the output of the above Program
Hi welcome to the game, This is a number guessing game.
5
You got 7 chances to guess the number. Let's start the game
Please Enter your Guess : 50
Your guess is lesser
Please Enter your Guess : 65
Your guess is lesser
Please Enter your Guess : 70
Your guess is lesser
Please Enter your Guess : 90
Your guess is lesser
Please Enter your Guess : 96
Your guess is higher
Please Enter your Guess : 92
Your guess is higher
Please Enter your Guess : 91
The number is 91 and you found it right !! in the 7 attempt
Method 2:

import random

n = random.randrange(1,10)

guess = int(input("Enter any number: "))

while n!= guess:

if guess < n:

print("Too low")

guess = int(input("Enter number again: "))

elif guess > n:

print("Too high!")

guess = int(input("Enter number again: "))

else:

break

print("you guessed it right!!")


Enter any number: 2
Too low
6
Enter number again: 5
Too low
Enter number again: 8
you guessed it right!!

This is the online compiler you can copy the above code and
paste in online compiler.
https://www.onlinegdb.com/online_python_compiler
To enjoy the Game below is link follow it and run the number guess game.

https://onlinegdb.com/85VZQE72n

You might also like