[go: up one dir, main page]

0% found this document useful (0 votes)
297 views8 pages

Guessing Number Game

The document describes a number guessing game project implemented in Python. The goal is to have the user guess a randomly generated number between 1-100 within a certain number of chances. If the guess is wrong, the program indicates whether the number was too high or low. If correct, the user wins. The project implements the game logic, gets user input, and indicates if the user won or lost after exhausting their chances. It also allows the user to play again after each round.

Uploaded by

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

Guessing Number Game

The document describes a number guessing game project implemented in Python. The goal is to have the user guess a randomly generated number between 1-100 within a certain number of chances. If the guess is wrong, the program indicates whether the number was too high or low. If correct, the user wins. The project implements the game logic, gets user input, and indicates if the user won or lost after exhausting their chances. It also allows the user to play again after each round.

Uploaded by

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

WACHEMO UNIVERSITY

SCHOOL OF COMPUTING AND INFORMATICS

DEPARTMENT OF COMPUTER SCIENCE

ARTIFICIAL INTELLIGENCE MINI PROJECT

TITLE: - “NUMBER GUESSING GAME”

Submitted By: 4th Year Section ‘A’_Group_6 Students

Student Name Id_No

1. Abebe Berhanu…………………………………………………R/ET-5378/09

2. Ezedin Lalo….…………………………………………………. R/ET-5618/09

3. Negese Sayile……………………………………………………. R/ET-5868/09

4. Mohammed Shemsu……………………………………………...R/ET-5836/09

5. Biruk Mitiku………………………………………………………R/ET-5532/09

Submitted To: Mrs. Tseganesh M.

January, 2020

Hosanna, Ethiopia
Table of Contents
1. Introduction...........................................................................................................................3

2. Statement of the problem which include the Steps of problem solving (such as Goal
formulation, Problem formulation, Search, and Execute/ Solution)...........................................3

2.1 Goal Formulation..........................................................................................................3

2.2 Problem Formulation.....................................................................................................3

2.3 Search............................................................................................................................3

2.4 Execute..........................................................................................................................3

3. Objective of the project........................................................................................................3

4. Related works.......................................................................................................................4

5. The brief description of the system......................................................................................4

5.1 The brief descriptions of your system’s PAGE (Percepts, Actions, Goals, and
Environment)...........................................................................................................................4

5.2 The brief descriptions of your system’s PEAS (Performance measure, Environment,
Actuators, and Sensors)...........................................................................................................5

6. Implementation of the project...............................................................................................5

7. References.............................................................................................................................6

8. Appendix: - Appendix A: Full Source Code........................................................................7

Page | 2
1. Introduction
The program will select a number between some range of integer numbers, then the user will
keep making guesses of what the number is until the numbers match in a given number of
chances. If the guess is incorrect, then the program tells the user whether the guess was higher or
lower than the selected integer number and reduces the number of chances of a guess. The user
wins the game if he/she gets the correct answer before number of chances come to end
otherwise, he/she loses.

2. Statement of the problem which include the Steps of problem solving


(such as Goal formulation, Problem formulation, Search, and Execute/
Solution).
2.1 Goal Formulation
Getting the correct random number/answer.

2.2 Problem Formulation


- Initial state- starting to guess
- States – number of chances to guess
- Operators/Actions- entering numbers

2.3 Search
- average of numbers from guessed and told to guess

2.4 Execute
- entering the average numbers

3. Objective of the project


- The objective of this mini project is entertaining and making fun of ourselves
and others by developing a simple guessing number game in python.
- Create a guessing game that told you if the number you put in was higher or
lower than the guess and then congratulated you when the number was correct.
- To have a correct loop that worked in the right way.

Page | 3
4. Related works
The game is two-person game called "Guess the Number". The first player thinks of an integer
within a known range. The second player tries to guess the number. If the guess is incorrect, then
the first player tells the second player whether the guess was too high or too low. Eventually, the
second player guesses the correct number. The second player's score equals the number of
guesses he made. The players then reverse their roles and repeat the game. The winner is the
player who gets the correct answer with the fewest guesses.

The key strategy in this game is to generate a clever guess. If, for example, the second player
knows the number is between 0 and 100, then a reasonable first guess is 50. This choice evenly
splits the range, giving you the maximum amount of information about the next guess. If the first
player says the guess is too low, then the second player splits the reduced range and guesses 75.
If the player says the guess is too high, then the optimal guess is 25. It can be shown that by
splitting the remaining range in half after each guess, it will, at worst, take the second player no

more than guesses to find the unknown number where is the initial range. So, if the

unknown number lies between 0 and 7, then it can be guessed in no more than
guesses[ CITATION 20Ja1 \l 1033 ].

5. The brief description of the system


5.1 The brief descriptions of your system’s PAGE (Percepts, Actions,
Goals, and Environment)
Agent type Percept Action Goal Environment
Guessing Set of integer Entering the Getting the Computer,
number game numbers numbers exact number Game player

5.2 The brief descriptions of your system’s PEAS (Performance measure,


Environment, Actuators, and Sensors).
Agent type Performance Environment Actuator Sensor

Page | 4
measure
Guessing Exactly equal to Computer, Arm, Mouse Keyboard,
number game the selected Game player Screen
random number

6. Implementation of the project


 At first the system imports random number and select one in some specific intervals
and specifies number of chances to play the game
 Then it asks the player to enter his/her name
 After that it asks the player to enter his/her guess between 1 and 100
 if the guess is greater than the selected random number it tells the player to enter less
number than the entered guess and decreases the number of chances by 1
 Else if the guess is less than the selected random number it tells the player to enter
greater number than the entered guess and decreases the number of chances by 1
 else if the guess matches with the selected random number, it congrats the player and
tells he/she entered exactly equal guess with the selected random number
 and else if the number of chances end before entering the right selected random
number, it displays the player has lost the game and tells what the selected random
number was
 at the last it asks the player whether he/she want to play again. If the answer is yes it
restarts the game and if the answer is no it terminates.

7. References

[1] 19 Januay 2020. [Online]. Available: https://www3.nd.edu/~lemmon/courses/ee224/web-


manual/web-manual/lab6/node4.html.

Page | 5
[2] 10 January 2020. [Online]. Available: https://github.com/hardikvasa/guess-the-number-
game.

8. Appendix: - Appendix A: Full Source Code


# Number guessing game
from random import randint #To generate a random number
name = input("Please Enter your name: ")
print("Welcome to my Number game, " + name)
def game():
Page | 6
rand_number = randint(0,500) #Generates a random number
print("\nI have selected a number between 0 and 500...")
print("You have 10 chances to guess that number...")
i=1
r=1
while i<=10: #10 Chances to the user
user_number = int(input('Enter your number: '))
if user_number < rand_number:
print("\n" + name + ", My number is greater than your guessed number")
print("you have " + str(10-i)+ " chances left" )
i = i+1
elif user_number > rand_number:
print("\n" + name + ", My number is less than your guessed number")
print("you have " + str(10-i)+ " chances left" )
i = i+1
elif user_number == rand_number:
print("\nCongratulations "+name+"!! You have guessed the correct number!")
r = 0;
break
else:
print("This is an invalid number. Please try again")
print("you have " + str(10-i)+ " chances left" )
continue
if r==1:
print("Sorry you lost the game!!")
print("My number was = " + str(rand_number))

def main():
game()
while True:
another_game = input("Do you wish to play again?(y/n): ")

Page | 7
if another_game == "y":
game()
else:
break
main()
print("\nEnd of the Game! Thank you for playing!")[ CITATION 20Ja2 \l 1033 ].

Page | 8

You might also like