0% found this document useful (0 votes)
3 views13 pages

Python Project

The document outlines a Python project for a number guessing game that utilizes basic AI concepts, specifically the binary search algorithm, to guess a number chosen by the computer. It details the project's objectives, requirements, implementation steps, and provides sample code. Additionally, it discusses the learning outcomes, potential improvements, and includes a bibliography for further reference.

Uploaded by

dullomishti1215
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)
3 views13 pages

Python Project

The document outlines a Python project for a number guessing game that utilizes basic AI concepts, specifically the binary search algorithm, to guess a number chosen by the computer. It details the project's objectives, requirements, implementation steps, and provides sample code. Additionally, it discusses the learning outcomes, potential improvements, and includes a bibliography for further reference.

Uploaded by

dullomishti1215
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

Number Guessing Game Python Project

Introduction
This project demonstrates how basic artificial
intelligence (AI) concepts can be applied in a
simple number guessing game.
The AI acts as the player and tries to guess a
number chosen by the computer using logical
thinking (binary search method).
The game can be implemented with basic Python
concepts like random number generation, loops,
and conditional statements.

pg. 1
Number Guessing Game Python Project

Project Objectives:
 To understand how AI can make
decisions.

 To create an interactive game using


Python.

 To apply logical reasoning (like AI) to


guess the correct number.

pg. 2
Number Guessing Game Python Project

Requirements:
 Python (Version 3 or above)

 Any code editor (IDLE, VS Code, etc.)

How the Game Works:

1. The computer randomly selects a number


between 1 and 100.

2. The AI (computer player) tries to guess the


number using smart guesses.

3. After each guess, it checks whether the


number is higher or lower.

4. It continues guessing until it finds the


correct number.

pg. 3
Number Guessing Game Python Project

AI Logic Used:

1. The AI uses a Binary Search Algorithm:

2. It guesses the middle number in the range.

3. If the guess is too low, it increases the lower


limit.

4. If the guess is too high, it decreases the


upper limit.

5. This method helps guess the number in


fewer steps (like how AI narrows down
options).

pg. 4
Number Guessing Game Python Project

Python Code:
import random

def ai_guess_number():
print("Welcome to the AI Number Guessing Game!")
print("The computer will choose a number between 1 and
100.")
print("Then the AI will try to guess it.")

# Computer chooses a random number


number_to_guess = [Link](1, 100)

low = 1
high = 100
attempts = 0

while True:
# AI guesses the middle number
guess = (low + high) // 2
attempts += 1
print(f"AI guesses: {guess}")

pg. 5
Number Guessing Game Python Project

if guess == number_to_guess:
print(f"AI found the number {guess} in {attempts}
attempts!")
break
elif guess < number_to_guess:
print("Too low!")
low = guess + 1
else:
print("Too high!")
high = guess - 1

# Run the game


ai_guess_number()

pg. 6
Number Guessing Game Python Project

Explanation:
 [Link](1, 100) is used to choose
the secret number.

 The AI starts with a range from 1 to 100.

 It uses the average of the current range to


make a guess.

 Based on the result, it narrows the range


using binary search.

pg. 7
Number Guessing Game Python Project

Output Sample:
Welcome to the AI Number Guessing Game!
The computer will choose a number between 1
and 100.
Then the AI will try to guess it.
AI guesses: 50
Too low!
AI guesses: 75
Too high!
AI guesses: 62
Too low!
AI guesses: 68
Correct!
AI found the number 68 in 4 attempts!

pg. 8
Number Guessing Game Python Project

Applications of AI:
 AI helps in solving problems by narrowing
down possibilities.

 Similar logic is used in searching, decision-


making, and games like chess.

 Real-life applications include search


engines, recommendation systems, and smart
assistants.

pg. 9
Number Guessing Game Python Project

Learning Outcomes:
 Understood basic AI logic (binary search).

 Learned how computers can make smart


guesses.

 Developed a Python program using loops


and conditions.

 Realized how AI can improve efficiency in


solving problems.

pg. 10
Number Guessing Game Python Project

Suggestions for Improvement:


1. Add user interaction for guessing.

2. Make AI guess in a larger range (1–1000).

3. Add a timer to see how fast AI can guess.

pg. 11
Number Guessing Game Python Project

Conclusion
Through this project, I gained valuable knowledge
of how Python programming and AI can work
together. I also learned about loops, conditional
statements, and logic building, which are essential
in software development. This project shows how
even small programs can use AI thinking to solve
problems intelligently.

Overall, this project was educational, enjoyable,


and a great introduction to basic AI and Python
programming.

pg. 12
Number Guessing Game Python Project

Bibliography
1. Python Official Documentation –
[Link]

2. W3Schools Python Tutorial –


[Link]

[Link] – Python Programming –


[Link]
language/
4. Stack Overflow – [Link] (for
troubleshooting code)

5. CBSE IT Textbook Class 9 – Artificial Intelligence and


Python Basics

6. YouTube Tutorials – Programming with Mosh,


CodeWithHarry (Python Basics)

7. Personal class notes and teacher guidance

pg. 13

You might also like