0% found this document useful (0 votes)
10 views19 pages

CS Project

The document contains an acknowledgment section expressing gratitude to various individuals for their support in a project focused on Python programming. It includes an introduction to Python, its features, applications, and a project aimed at developing five interactive games to enhance programming skills. The document also provides code examples for games like 'Guess the Number', 'Hangman', and 'XO' (Tic Tac Toe).
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)
10 views19 pages

CS Project

The document contains an acknowledgment section expressing gratitude to various individuals for their support in a project focused on Python programming. It includes an introduction to Python, its features, applications, and a project aimed at developing five interactive games to enhance programming skills. The document also provides code examples for games like 'Guess the Number', 'Hangman', and 'XO' (Tic Tac Toe).
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

ACKNOWLEDGMENT

I would like to express my deep sense of gratitude and


sincere thanks to my project guide, Ms. Shabnam Naim, for her
invaluable guidance throughout the course of this project. She
consistently showed keen interest in my work, and her constructive
advice, constant encouragement, and motivation played a vital role
in the successful completion of this project.

I extend my heartfelt thanks to Ms. Safeena Parveen, our


respected Principal of Al-Hira Model School, for her coordination
and for extending every possible support required for completing
this project.

I am also grateful to my parents for their continuous


motivation, encouragement, and support. I would like to thank my
classmates for their timely help and cooperation during the
compilation of this project.

Last but not the least, I sincerely thank all those who have
helped me directly or indirectly towards the successful completion
of this project.
INDEX

[Link] CONTENT PAGE NO.


1. Introduction to Python 1
2. Introduction and Aim of 5
Python
3. Guess the number 6
5. Hangman 7
6. XO 10
7. Memory game 14
8. Bibliography
INTRODUCTION TO PYTHON

Understanding Python and Its Importance

Python is one of the most popular and widely used programming


languages in the world today. It is a high-level programming language,
which means it is closer to human language and easier to understand
compared to low-level programming languages. Python was designed to
be simple, readable, and efficient, making it an excellent choice for
beginners as well as professionals. The main idea behind Python is that
coding should be clear and logical so that programmers can focus more
on solving problems rather than worrying about complex syntax rules.

Python is also an interpreted language. This means Python code is


executed line by line rather than being converted into machine code all
at once before running. Because of this, Python makes debugging easier
since errors can be found quickly. Python is also open-source, meaning
anyone can use it for free, modify it, and contribute to its development.
Due to its simplicity and powerful capabilities, Python is used in many
modern technologies like artificial intelligence, data science, automation,
web development, and software development.

Another reason Python is important is its large community support.


Millions of developers around the world use Python and continuously
create tutorials, tools, and libraries. Libraries are pre-written codes that
help programmers perform tasks faster. For example, instead of writing
hundreds of lines of code, a programmer can use a library to complete
tasks in just a few lines. This makes Python extremely powerful and
time-saving.

Important Points:
●​ Python is easy to learn and beginner-friendly.
●​ It is an interpreted and high-level programming language.
●​ It is free and open source.
●​ It has a large global community.
●​ It is used in modern technologies and industries.
Features and Applications of Python

Python has many features that make it unique and useful. One of the
most important features is its simple syntax. Python code is written in a
way that looks similar to English sentences. This makes it easy to read
and understand even for someone who is new to programming. Another
important feature is dynamic typing. In Python, you do not need to
declare the data type of a variable. Python automatically understands
whether the variable contains a number, text, or another type of data.

Python is also platform-independent. This means Python programs can


run on different operating systems like Windows, macOS, and Linux
without major changes. Python also supports multiple programming
styles such as procedural programming, object-oriented programming,
and functional programming. This flexibility makes Python suitable for
many types of projects.

Python is used in many real-world applications. In web development,


Python helps build websites and web applications. In data science,
Python is used to analyze and visualize large amounts of data. In
artificial intelligence and machine learning, Python helps create smart
systems that can learn and make decisions. Python is also used in
automation to perform repetitive tasks like file management, data entry,
and email automation. Many companies use Python because it
increases productivity and reduces development time.

Important Points:
●​ Simple and readable syntax.
●​ Automatically detects data types.
●​ Works on multiple operating systems.
●​ Used in AI, data science, web development, and automation.
●​ Supports different programming styles.
Basics of Python Programming

Python programming starts with understanding basic syntax and


structure. Python uses indentation (spaces) instead of brackets to define
blocks of code. This makes Python code look neat and organized.
Python is also case-sensitive, meaning variable names like Name and
name are treated as different variables.

Variables are used to store data. In Python, variables are created when
a value is assigned to them. Python automatically decides the data type
of the variable. Common data types include integers (whole numbers),
floats (decimal numbers), strings (text), and booleans (True or False
values). Python also has collection data types such as lists, tuples, sets,
and dictionaries which are used to store multiple values.

Python programs often require input and output. Input allows the user to
enter data into the program, while output displays results. Python uses
simple functions to handle input and output, making it easy to interact
with users. Python also provides operators to perform mathematical
calculations, compare values, and combine conditions.

Control statements are used to control the flow of a program. Conditional


statements like if, else, and elif allow programs to make decisions. Loops
like for loops and while loops allow programs to repeat tasks multiple
times. These concepts are very important in programming because they
help automate tasks and solve complex problems efficiently.

Important Points:
●​ Python uses indentation for code structure.
●​ Variables store data.
●​ Python supports many data types.
●​ Input and output help interact with users.
●​ Control statements help programs make decisions.

Functions, Advantages, and Limitations of Python


Functions are reusable blocks of code that perform specific tasks.
Functions help reduce code repetition and make programs more
organized. In Python, functions are defined using the def keyword.
Functions can take input values, process them, and return output values.
Using functions makes large programs easier to manage and
understand.

Python has many advantages. It is easy to learn, which makes it suitable


for beginners. Python allows programmers to write programs faster
compared to many other languages. It has a large number of libraries
that help perform complex tasks easily. Python is also widely used in
industries, making it valuable for career opportunities. Many new
technologies like artificial intelligence and data science heavily depend
on Python.

However, Python also has some limitations. Python programs can be


slower compared to some other programming languages because it is
interpreted. Python is also not always preferred for mobile app
development or high-performance gaming where speed is extremely
important. Python can also use more memory compared to some
low-level languages.

Even with these limitations, Python is still one of the most powerful and
useful programming languages today. It is continuously growing and
improving. Learning Python provides a strong foundation for learning
other programming languages and understanding modern technology.

Important Points:
●​ Functions help organize and reuse code.
●​ Python is easy to learn and widely used.
●​ Python has many libraries and tools.
●​ Python may be slower in some cases.
●​ Python is important for future technologies.
INTRODUCTION AND AIM OF THE PROJECT

INTRODUCTION
Games play a significant role in the field of computer science
as they combine logic, creativity, and problem-solving skills.
Programming games helps in understanding core concepts such as
algorithms, control structures, variables, and user interaction in an
engaging and practical manner.
This group project focuses on the development of five simple
games using programming codes. Each game is designed to
demonstrate different programming concepts while providing an
interactive experience for the user. Through this project, we apply
theoretical knowledge of coding into real-time applications,
enhancing our logical thinking and teamwork skills.
The project also encourages collaboration among group
members, as tasks such as coding, testing, debugging, and
documentation are shared to achieve a common goal.

AIM OF THE PROJECT


The main aim of this project is to design and implement five
interactive games using programming concepts.
The specific objectives of the project are:
●​ To understand and apply basic programming concepts through
game development
●​ To improve logical thinking and problem-solving skills
●​ To gain practical experience in writing, testing, and debugging
code
●​ To promote teamwork and collaborative learning
●​ To develop simple, user-friendly games for educational and
entertainment purposes
PROJECT CODES

1.​GUESS THE NUMBER

PROJECT CODE:
import random

secret_number = [Link](1, 100)


attempts = 0
max_attempts = 10

🎮
print(" Welcome to the Number Guessing Game!")
print("Guess a number between 1 and 100")
print("You have only 10 attempts. Good luck!\n")

while attempts < max_attempts:


guess = int(input("Enter your guess: "))
attempts += 1

📉
if guess < secret_number:
print(" Too low! Try again.\n")

📈
elif guess > secret_number:
print(" Too high! Try again.\n")

🎉
else:

🎊
print(f" Congratulations! You guessed the number in
{attempts} attempts ")
break

💔
else:

🔐
print(" Game Over!")
print(f" The correct number was: {secret_number}")

🎮
OUTPUT:
Welcome to the Number Guessing Game!
Guess a number between 1 and 100
You have only 10 attempts. Good luck!

📉
Enter your guess: 20
Too low! Try again.

📉
Enter your guess: 40
Too low! Try again.

📈
Enter your guess: 60
Too high! Try again.

📉
Enter your guess: 50
Too low! Try again.

📉
Enter your guess: 55
Too low! Try again.

📉
Enter your guess: 57
Too low! Try again.

📈
Enter your guess: 59
Too high! Try again.

🎉 🎊
Enter your guess: 58
Congratulations! You guessed the number in 8 attempts

[Process completed - press Enter]

2.​ HANGMAN

PROJECT CODE:
import random

words = [
"apple","banana","orange","grape","mango","papaya","guava","peac
h","pear","plum",
"cherry","lemon","melon","berry","coconut","fig","date","kiwi","apricot
","avocado",
"school","college","teacher","student","class","exam","result","projec
t","subject","library",
"python","coding","program","computer","keyboard","mouse","scree
n","internet","software","hardware",
"science","physics","chemistry","biology","math","algebra","geometr
y","history","geography","english",
"planet","galaxy","earth","venus","mars","jupiter","saturn","uranus","
neptune","mercury",
"animal","tiger","lion","elephant","giraffe","zebra","monkey","rabbit","
horse","donkey",
"flower","rose","lily","tulip","lotus","jasmine","orchid","sunflower","dai
sy","marigold"
]

word = [Link](words)
guessed_letters = []
attempts = 6

🎯
print(" Welcome to HANGMAN")
print("Guess the word letter by letter")
print("You have 6 wrong attempts\n")

while attempts > 0:


display_word = ""
for letter in word:
if letter in guessed_letters:
display_word += letter + " "
else:
display_word += "_ "

print("Word:", display_word.strip())
🎉
if "_" not in display_word:

🎊
print("\n Congratulations! You guessed the word correctly
")
break

guess = input("Enter a letter: ").lower()

⚠️
if guess in guessed_letters:
print(" You already guessed that letter.\n")
continue

guessed_letters.append(guess)

if guess not in word:


attempts -= 1
print(f" Wrong guess! Attempts left: {attempts}\n")


else:
print(" Good guess!\n")

💔 Game Over!")
else:

🔐 The word was:", word)


print("
print("

🎯
OUTPUT:
Welcome to HANGMAN
Guess the word letter by letter
You have 6 wrong attempts

Word: _ _ _ _ _ _ _ _


Enter a letter: a
Good guess!

Word: _ _ _ _ _ a _ _
Enter a letter: e
✅ Good guess!

Word: e _ e _ _ a _ _


Enter a letter: l
Good guess!

Word: e l e _ _ a _ _


Enter a letter: p
Good guess!

Word: e l e p _ a _ _


Enter a letter: h
Good guess!

Word: e l e p h a _ _


Enter a letter: n
Good guess!

Word: e l e p h a n _


Enter a letter: t
Good guess!

Word: e l e p h a n t

🎉 Congratulations! You guessed the word correctly 🎊


[Process completed - press Enter]

3.​XO

PROJECT CODE:
board = [" " for _ in range(9)]

def display_board():
print()
print(board[0], "|", board[1], "|", board[2])
print("--+---+--")
print(board[3], "|", board[4], "|", board[5])
print("--+---+--")
print(board[6], "|", board[7], "|", board[8])
print()

def check_winner(player):
win_combinations = [
[0,1,2],[3,4,5],[6,7,8],
[0,3,6],[1,4,7],[2,5,8],
[0,4,8],[2,4,6]
]
for combo in win_combinations:
if all(board[i] == player for i in combo):
return True
return False

def board_full():
return " " not in board

current_player = "X"

🎮
print(" Welcome to XO (Tic Tac Toe)")
print("Positions are from 1 to 9")

while True:
display_board()

try:
move = int(input(f"Player {current_player}, choose a position
(1-9): ")) - 1

⚠️
except ValueError:
print(" Please enter a number from 1 to 9.")
continue

⚠️
if move < 0 or move > 8:
print(" Position must be between 1 and 9.")
continue

⚠️
if board[move] != " ":
print(" Position already taken. Try again.")
continue

# Place move
board[move] = current_player

# Check win
if check_winner(current_player):

🎉
display_board()
print(f" Player {current_player} wins!")
break

# Check draw
if board_full():

🤝
display_board()
print(" It's a draw!")
break

#switch player
current_player = "O" if current_player == "X" else "X”

🎮
OUTPUT:
Welcome to XO (Tic Tac Toe)
Positions are from 1 to 9

| |
--+---+--
| |
--+---+--
| |

Player X, choose a position (1-9): 1

X| |
--+---+--
| |
--+---+--
| |

Player O, choose a position (1-9): 2

X|O|
--+---+--
| |
--+---+--
| |

Player X, choose a position (1-9): 3

X|O|X
--+---+--
| |
--+---+--
| |

Player O, choose a position (1-9): 5

X|O|X
--+---+--
|O|
--+---+--
| |
Player X, choose a position (1-9): 4

X|O|X
--+---+--
X|O|
--+---+--
| |

Player O, choose a position (1-9): 8

X|O|X
--+---+--
X|O|
--+---+--
|O|

🎉 Player O wins!
[Process completed - press Enter]

4.​MEMORY GAME

PROJECT CODE:
import random
import time

numbers = [Link](range(1, 101), 5)

🎮
🧠
print(" MEMORY GAME")
print(" Memorize the numbers in the exact order:")
print(numbers)

[Link](6)
print("\n" * 50)

attempts = 2

while attempts > 0:

user_input = input(" ⌨️ Enter the numbers in order


(space-separated): ")

user_numbers = list(map(int, user_input.split()))

correct_positions = []

for i in range(5):
if user_numbers[i] == numbers[i]:
correct_positions.append(user_numbers[i])

🎉 ✅")
if user_numbers == numbers:
print(" Perfect! You remembered everything correctly
break

⚠️
elif sorted(user_numbers) == sorted(numbers):

📌
print(" All numbers are correct, but the order is wrong!")
print(" Correctly placed numbers:", correct_positions)

attempts -= 1

🔁
if attempts > 0:
print(" Try once more!\n")


else:

🔢
print(" No attempts left.")
print(" Correct sequence was:", numbers)

❌ Some numbers are incorrect.")


else:
print("
📌 Correctly placed numbers:", correct_positions)
💀 Game Over!")
print("

🔢 Correct sequence was:", numbers)


print("
print("
break

🎮
OUTPUT:

🧠
MEMORY GAME
Memorize the numbers in the exact order:
[42, 2, 49, 99, 90]

⌨️ Enter the numbers in order (space-separated): 44 2 49 99 90


❌ Some numbers are incorrect.
📌 Correctly placed numbers: [2, 49, 99, 90]
💀 Game Over!
🔢 Correct sequence was: [42, 2, 49, 99, 90]
[Process completed - press Enter]
BIBLIOGRAPHY

1.​[Link]
p
2.​[Link]
o-python/
3.​[Link]
4.​[Link]
mentation-automatic-tic-tac-toe-game-using-random
-number/
5.​[Link]
mory-puzzle-game-using-pygame/
6.​[Link]
sing-game-in-python/

You might also like