[go: up one dir, main page]

0% found this document useful (0 votes)
2 views29 pages

Cp-i Lab Manual Python Final (1)

The document is a lab manual for Python programming practicals for first-year computer engineering students at Alard University. It includes a series of practical exercises covering various programming concepts such as salary calculation, list statistics, student grading, and string operations, each with objectives, problem statements, algorithms, source code, and observations. The manual is authored by Prof. Ganesh S. Wayal and requires Python 3 and an IDE for execution.
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)
2 views29 pages

Cp-i Lab Manual Python Final (1)

The document is a lab manual for Python programming practicals for first-year computer engineering students at Alard University. It includes a series of practical exercises covering various programming concepts such as salary calculation, list statistics, student grading, and string operations, each with objectives, problem statements, algorithms, source code, and observations. The manual is authored by Prof. Ganesh S. Wayal and requires Python 3 and an IDE for execution.
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/ 29

Lab Manual for

Python Programming Practicals

Course Name: CP-I

Semester: I

First Year

Department of Computer Engineering

Alard University

By: Prof. Ganesh S. Wayal


Index

Practical Title Page


No. No.

1 To calculate the salary of an employee with allowances and 4


deductions

2 To accept a list of N numbers and display maximum, 6


minimum, sum, and average

3 To compute the result and grade based on a student's five 8


course marks

4 To create a simple calculator with basic arithmetic operations 10


and special functions

5 To compute square, cube, square root, prime check, factorial, 12


and prime factors

6 To check if a number is an Armstrong number 14

7 To perform various string operations on a given input string 16

8 To create an EMPLOYEE class with specific attributes and 18


operations

By: Prof. Ganesh S. Wayal


9 To copy contents of one file to another with character 20
replacements

10 To create a STORE class to manage products and generate a 22


bill

Mini Calculator with GUI supporting basic and complex functions 24


Project - a

Mini Program to simulate rolling dice 26


Project - b

Mini Tic Tac Toe game using GUI for two players 28
Project - c

Each practical is structured as follows:


● Objective: Brief overview of what the practical aims to achieve.
● Problem Statement: Detailed description of the task or requirements.
● Algorithm: Step-by-step instructions to solve the problem.
● Flowchart : Visual representation of the algorithm.
● Source Code: Complete Python code for the solution.
● Sample Input and Output: Examples of inputs and expected outputs.
● Observations: Key points observed during execution.
● Conclusion: Summary of the outcomes and functionality.

Apparatus/Software Required:
● A computer with Python 3 installed.
● Python IDE (like PyCharm, Jupyter Notebook, or any text editor with Python
support).

By: Prof. Ganesh S. Wayal


Practical 1: Calculate Salary of an Employee
Objective:
To develop a Python program that calculates the gross and net salary of an employee
based on their basic pay and specific deductions.

Problem Statement:
Write a program that takes the basic pay of an employee as input and calculates the
Gross Salary and Net Salary. The calculations include:

● House Rent Allowance (HRA) is 10% of basic pay.


● Travel Allowance (TA) is 5% of basic pay.
● Professional Tax is 2% of the Gross Salary.

The formulae for the calculations are:

● Gross Salary = Basic Pay + HRA + TA


● Net Salary = Gross Salary - Professional Tax

Apparatus/Software Required:
● A computer with Python 3 installed.
● Python IDE (like PyCharm, Jupyter Notebook, or any text editor with Python
support).

Algorithm:
1. Start the program.
2. Prompt the user to input the basic pay of the employee.
3. Calculate HRA as 10% of the basic pay.
4. Calculate TA as 5% of the basic pay.
5. Calculate the Gross Salary as the sum of basic pay, HRA, and TA.
6. Calculate Professional Tax as 2% of the Gross Salary.
7. Calculate the Net Salary by subtracting the Professional Tax from the Gross
Salary.
8. Display the Gross Salary and Net Salary.
9. End the program.

Source Code:

Input and Output:

By: Prof. Ganesh S. Wayal


Observations:
1. As the basic pay increases, both HRA and TA increase proportionately.
2. The professional tax, being a percentage of gross salary, increases with higher
basic pay, reducing the net salary accordingly.

Conclusion:
The program successfully calculates the Gross and Net Salary of an employee based
on their basic pay, including allowances and deductions.

By: Prof. Ganesh S. Wayal


Practical 2: Compute List Statistics
I. Objective:
To develop a Python program that accepts a list of numbers from the user and
calculates the maximum, minimum, sum, and average of the numbers.

II. Problem Statement:


Write a program that takes N numbers from the user, stores them in a list, and
calculates:

● Maximum value in the list.


● Minimum value in the list.
● Sum of all values in the list.
● Average of values in the list.

The program should output each of these values.

III. Algorithm:
1. Start the program.
2. Prompt the user to input the number of elements (N).
3. Initialize an empty list to store the numbers.
4. Using a loop, accept N numbers from the user and store each number in the
list.
5. Calculate the maximum value in the list using the max() function.
6. Calculate the minimum value in the list using the min() function.
7. Calculate the sum of all elements in the list using the sum() function.
8. Calculate the average of the list by dividing the sum by N.
9. Display the maximum, minimum, sum, and average of the list.
10. End the program.

IV. Source Code:

Write Source code Here

V. Input and Output:

By: Prof. Ganesh S. Wayal


VI. Observations:
1. The program accurately calculates and displays the maximum, minimum, sum,
and average for the given list.
2. The program handles decimal values correctly when calculating the average.

VII. Conclusion:
The program successfully accepts a list of numbers from the user, then computes and
displays the maximum, minimum, sum, and average of those numbers.

By: Prof. Ganesh S. Wayal


Practical 3: Calculate Student Result and Grade
Objective:
To develop a Python program that accepts a student’s marks for five courses,
determines if the student has passed, and calculates their grade based on the aggregate
percentage.

Problem Statement:
Write a program that:

● Takes the marks of five courses as input.


● Checks if the student has passed all courses (passing marks = 40 for each
course).
● Calculates the aggregate percentage.
● Determines the grade based on the aggregate percentage:
○ Distinction: Aggregate ≥ 75%
○ First Division: 60% ≤ Aggregate < 75%
○ Second Division: 50% ≤ Aggregate < 60%
○ Third Division: 40% ≤ Aggregate < 50%
○ Fail: Aggregate < 40% or if marks in any subject are below 40

Apparatus/Software Required:
● A computer with Python 3 installed.
● Python IDE (like PyCharm, Jupyter Notebook, or any text editor with Python
support).

Algorithm:
1. Start the program.
2. Prompt the user to enter the marks for five courses.
3. Check if the student has scored at least 40 marks in each course:
○ If any mark is less than 40, the student fails.
4. Calculate the aggregate percentage as the average of the five course marks.
5. Determine the grade based on the aggregate percentage:
○ If aggregate ≥ 75%, assign “Distinction.”
○ If 60% ≤ aggregate < 75%, assign “First Division.”
○ If 50% ≤ aggregate < 60%, assign “Second Division.”
○ If 40% ≤ aggregate < 50%, assign “Third Division.”
6. Display the pass/fail status, aggregate percentage, and grade.
7. End the program.

By: Prof. Ganesh S. Wayal


Flowchart:

Source Code:

Input and Output:

Observations:
1. The program accurately identifies if the student has passed or failed based on
the marks of each course.
2. The program calculates the aggregate percentage and assigns the correct grade
based on the specified criteria.

Conclusion:
The program successfully calculates the aggregate percentage of a student's marks,
checks pass/fail status for individual courses, and assigns an appropriate grade based
on the aggregate.

By: Prof. Ganesh S. Wayal


Practical 4: Simple Calculator with Special Operations
Objective:
To develop a Python program that simulates a simple calculator capable of performing
basic operations (addition, subtraction, multiplication, and division) as well as special
operations (exponentiation and factorial).

Problem Statement:
Write a program that allows the user to:

● Perform basic arithmetic operations: addition, subtraction, multiplication, and


division.
● Perform special operations:
○ Exponentiation (xyx^yxy)
○ Factorial of a number (x!x!x!)

The program should display the result of the chosen operation.

Algorithm:
1. Start the program.
2. Display a menu for the user to select an operation:
○ 1: Addition
○ 2: Subtraction
○ 3: Multiplication
○ 4: Division
○ 5: Exponentiation (xyx^yxy)
○ 6: Factorial (x!x!x!)
3. Take the user’s choice as input.
4. Based on the chosen operation, do the following:
○ If the operation is addition, subtraction, multiplication, or division,
take two numbers as input and perform the operation.
○ If the operation is exponentiation, take two numbers as input (base and
exponent) and calculate the power.
○ If the operation is factorial, take one number as input and calculate its
factorial.
5. Display the result of the operation.
6. End the program.

By: Prof. Ganesh S. Wayal


Flowchart:

Source Code:

Sample Input and Output:

Observations:
1. The program successfully performs basic arithmetic operations and special
operations as selected by the user.
2. The program handles division by zero and factorial for negative numbers,
displaying appropriate error messages.

Conclusion:
The program simulates a simple calculator that performs addition, subtraction,
multiplication, division, exponentiation, and factorial calculations based on the user's
choice.

By: Prof. Ganesh S. Wayal


Practical 5: Calculate Mathematical Functions Using Python
Objective:
To develop a Python program that performs various mathematical operations on a
user-given number, including:

● Calculating the square root


● Calculating the square and cube
● Checking if the number is prime
● Calculating the factorial
● Finding the prime factors

Problem Statement:
Write a program that:

1. Accepts a number from the user.


2. Calculates:
○ Square root of the number
○ Square of the number
○ Cube of the number
3. Checks if the number is prime.
4. Calculates the factorial of the number.
5. Finds the prime factors of the number.

The program should display each result clearly.

Algorithm:
1. Start the program.
2. Accept a number from the user.
3. Calculate the square root of the number using the math.sqrt() function.
4. Calculate the square of the number by multiplying it by itself.
5. Calculate the cube of the number by raising it to the power of 3.
6. Check if the number is prime by checking divisibility from 2 up to the square
root of the number.
7. Calculate the factorial of the number using the math.factorial()
function.
8. Find the prime factors of the number by:
○ Dividing by 2 until it is no longer divisible by 2.
○ Checking odd numbers from 3 upwards and dividing until no longer
divisible.
9. Display all the results.

By: Prof. Ganesh S. Wayal


10. End the program.

Flowchart:

Source Code:

Sample Input and Output:

Observations:
1. The program correctly calculates and displays the square root, square, and
cube of the input number.
2. It accurately checks if the number is prime and calculates its factorial.
3. It correctly determines the prime factors of the input number.

Conclusion:
The program successfully performs the required mathematical operations on a
user-given number, including calculating the square root, square, cube, checking for
primality, calculating the factorial, and determining the prime factors.

By: Prof. Ganesh S. Wayal


Practical 6: Check if a Number is an Armstrong Number
Objective:
To develop a Python program to check if a given three-digit number is an Armstrong
number.

Problem Statement:
Write a program that:

1. Accepts a three-digit number from the user.


2. Checks if the number is an Armstrong number.
○ An Armstrong number (also called a Narcissistic number) is a
three-digit number such that the sum of the cubes of its digits is equal
to the number itself.
○ For example, 371 is an Armstrong number because 33+73+13=3713^3
+ 7^3 + 1^3 = 37133+73+13=371.

Algorithm:
1. Start the program.
2. Take a three-digit number as input from the user.
3. Extract the digits of the number:
○ Divide the number by 100 to get the hundreds place digit.
○ Use modulus and division to get the tens place digit.
○ Use modulus to get the units place digit.
4. Calculate the sum of the cubes of the digits.
5. Check if the sum of the cubes of the digits is equal to the original number:
○ If they are equal, the number is an Armstrong number.
○ If they are not equal, the number is not an Armstrong number.
6. Display the result.
7. End the program.

Flowchart:

Source Code:

By: Prof. Ganesh S. Wayal


Sample Input and Output:

Observations:
1. The program successfully identifies Armstrong numbers.
2. The program correctly calculates the sum of the cubes of the digits and checks
if it matches the input number.
3. Edge cases such as numbers with zero digits (e.g., 370) are handled properly.

Conclusion:
The program effectively checks if a given three-digit number is an Armstrong number
by comparing the sum of the cubes of its digits with the original number.

By: Prof. Ganesh S. Wayal


Practical 7: Perform Various String Operations
Objective:
To develop a Python program that performs various operations on a user-input string,
including:

● Calculating the length of the string.


● Reversing the string.
● Checking equality of two strings.
● Checking if the string is a palindrome.
● Checking if a substring exists within the string.

Problem Statement:
Write a Python program that:

1. Accepts a string from the user.


2. Performs the following operations:
○ Calculate and display the length of the string.
○ Reverse and display the string.
○ Check if two input strings are equal.
○ Check if the input string is a palindrome.
○ Check if a specified substring exists within the input string.

Algorithm:
1. Start the program.
2. Input a string from the user.
3. Calculate the length of the string using the len() function and display it.
4. Reverse the string using slicing and display it.
5. Check equality:
○ Ask for a second string from the user.
○ Compare the original string with the second string and display whether
they are equal.
6. Check if the original string is a palindrome:
○ Compare the original string with its reverse.
○ If they are the same, display that the string is a palindrome; otherwise,
it is not.
7. Check if a substring exists within the original string:
○ Accept a substring from the user.
○ Use the in keyword to check if the substring exists in the string and
display the result.
8. End the program.

By: Prof. Ganesh S. Wayal


Flowchart:

Source Code:

Sample Input and Output:

Observations:
1. The program successfully calculates the length of the string and displays it.
2. The program correctly reverses the string and checks for palindrome
properties.
3. The program accurately checks for equality between two strings.
4. The program correctly identifies whether a substring exists within the input
string.

Conclusion:
The program effectively performs various operations on the user-given string,
including calculating its length, reversing it, checking equality with another string,
verifying if it is a palindrome, and finding a substring within it.

By: Prof. Ganesh S. Wayal


Practical 8: Class-Based Employee Management System in
Python
Objective:
To create a Python program using a class structure to manage employee records. The
program should:

1. Store details of each employee, including name, designation, gender, date of


joining, and salary.
2. Implement functionality to:
○ Count the total number of employees.
○ Count the number of male and female employees.
○ Display employees with a salary above a certain threshold.
○ Display employees with a specific designation.

Problem Statement:
Write a Python program that defines an Employee class to store and manipulate
details of employees. Define methods to:

1. Track the total number of employees in an organization.


2. Count male and female employees.
3. Display employees earning more than 10,000.
4. Display employees with the designation “Asst Manager.”

Algorithm:
1. Define the Employee class with the following attributes:
○ name: Employee's name
○ designation: Employee's designation
○ gender: Employee's gender
○ date_of_joining: Employee's joining date
○ salary: Employee's salary
2. Implement a class variable employee_count to keep track of the total
number of employees.
3. Define the following methods in the Employee class:
○ __init__: Initialize each employee object with the above attributes
and increment employee_count.
○ display_details: Display the details of the employee.
4. Define the following standalone functions:

By: Prof. Ganesh S. Wayal


○ count_male_female: Counts the number of male and female
employees.
○ employees_above_salary: Displays employees with a salary
greater than a specified amount.
○ employees_with_designation: Displays employees with a
specific designation.
5. Create instances of the Employee class based on user input and invoke the
appropriate functions.

Flowchart:

Source Code:

Sample Input and Output:

Observations:
1. The program accurately maintains and displays the total number of employees.
2. It correctly counts and displays the number of male and female employees.
3. It successfully identifies employees earning above a certain salary threshold.
4. It correctly filters employees by their designation.

Conclusion:
The program effectively demonstrates the use of classes and functions to manage
employee records, including counting, filtering, and displaying information based on
various criteria.

By: Prof. Ganesh S. Wayal


Practical 9: File Copy Program with Character Replacement
Objective:
To develop a Python program that copies the contents of one file to another with
specific character modifications:

1. Replace all full stops (.) with commas (,).


2. Convert all lowercase letters to uppercase.
3. Convert all uppercase letters to lowercase.

Problem Statement:
Write a Python program that:

1. Reads the contents of an existing file.


2. Creates a new file and copies the contents from the existing file with the
following modifications:
○ Replace each full stop (.) with a comma (,).
○ Convert all lowercase characters to uppercase.
○ Convert all uppercase characters to lowercase.

Algorithm:
1. Start the program.
2. Open the source file in read mode.
3. Read the content of the source file.
4. Process the content:
○ Replace all full stops (.) with commas (,).
○ Convert lowercase letters to uppercase.
○ Convert uppercase letters to lowercase.
5. Open the destination file in write mode.
6. Write the modified content to the destination file.
7. Close both files.
8. Display a message indicating that the file has been copied and modified
successfully.
9. End the program.

By: Prof. Ganesh S. Wayal


Flowchart:

Source Code:

Sample Input and Output:

Observations:
1. The program successfully reads content from the source file and applies the
required modifications.
2. The modified content is written correctly to the destination file.
3. The program handles cases where the source file may not exist.

Conclusion:
The program effectively copies the contents of a file to another with specified
character modifications, demonstrating file handling and string manipulation in
Python.

By: Prof. Ganesh S. Wayal


Practical 10: Product Store Management System Using
Classes

Objective:
To develop a Python program that uses a class-based approach to manage a store
inventory system. The program should:

1. Store details of products, including product code, name, and price.


2. Display a menu of all products to the user.
3. Allow the user to generate a bill based on selected products and quantities.

Problem Statement:
Write a Python program that defines a Product class to store and display product
details. Create a Store class that manages the inventory and provides a menu of
products to the user. Allow the user to place an order, specify the quantity of each
product, and generate a bill.

Algorithm:
1. Define the Product class with the following attributes:
○ product_code: Unique identifier for the product.
○ name: Name of the product.
○ price: Price of the product.
2. Define the Store class with the following attributes and methods:
○ Attributes:
■ A list of Product objects to store the inventory.
○ Methods:
■ add_product: Adds a product to the store.
■ display_menu: Displays the list of products with their
details.
■ generate_bill: Calculates the total bill based on the user’s
selected products and quantities.
3. Implement the main program:
○ Create instances of Product and add them to the Store.
○ Display the product menu.
○ Accept user input for products and quantities.
○ Generate and display the bill.

By: Prof. Ganesh S. Wayal


Flowchart:

Source Code:

Sample Input and Output:

Observations:
1. The program correctly displays the list of available products with their prices.
2. The program accepts multiple products and quantities from the user.
3. The program accurately calculates the total bill based on user-selected
products and quantities.

Conclusion:
The program successfully demonstrates the use of classes to manage product data and
generate a bill, illustrating object-oriented programming concepts in Python.

By: Prof. Ganesh S. Wayal


Mini Project - a:
GUI-Based Calculator with Basic and Complex Functions

Objective:
To design and develop a GUI-based calculator using Python that performs basic
arithmetic operations (addition, subtraction, multiplication, division) and complex
functions (power, square root, factorial, trigonometric operations).

Problem Statement:
Create a calculator program with a Graphical User Interface (GUI) in Python. The
calculator should support:

1. Basic arithmetic operations: addition, subtraction, multiplication, and division.


2. Complex functions: exponentiation (x^y), square root, factorial, and
trigonometric functions (sin, cos, tan).

Apparatus/Software Required:
● A computer with Python 3 installed.
● Python libraries: tkinter (for GUI), math (for complex functions).
● Python IDE (like PyCharm, Jupyter Notebook, or any text editor with Python
support).

Algorithm:
1. Import Required Libraries:
○ Import tkinter for creating the GUI.
○ Import math for complex functions.
2. Create the Main Calculator Window:
○ Initialize the main application window.
○ Set window title and size.
3. Design the Input and Display Area:
○ Use an Entry widget for the calculator display to show entered
numbers and results.
4. Define Button Layout:
○ Create buttons for numbers (0-9), basic operations (+, -, *, /), and
complex operations (sqrt, x^y, sin, cos, tan, factorial).
○ Arrange buttons in a grid layout.
5. Implement Event Handlers for Buttons:

By: Prof. Ganesh S. Wayal


○ Define functions for each button that updates the display with the
entered numbers or operators.
○ Define a function to calculate and display results based on the entered
expression.
○ Handle errors like division by zero and invalid input.
6. Run the Application Loop:
○ Start the main event loop to make the calculator window interactive.

Flowchart:

Source Code:

Sample Input and Output:


● GUI Calculator Interaction:
○ User clicks on numbers and operations to form expressions.
○ On pressing =, the result is displayed.
○ For trigonometric and other functions (like sqrt, factorial), user enters
the number and presses the corresponding function button.

Observations:
1. The calculator performs basic arithmetic accurately.
2. It handles complex functions like square root, factorial, and trigonometric
functions.
3. The GUI is interactive and user-friendly.

Conclusion:
The program successfully implements a GUI-based calculator using Python
tkinter, which supports both basic and advanced mathematical operations. This
project demonstrates effective use of GUI programming and math functions in
Python.

By: Prof. Ganesh S. Wayal


Mini Project - b: Dice Roll Simulator
Objective:
To develop a Python program that simulates rolling a pair of dice. The program
should:

1. Randomly generate numbers from 1 to 6 for each dice roll.


2. Display the outcome of each roll.
3. Allow the user to roll the dice multiple times.

Problem Statement:
Create a Python program with a graphical interface that simulates rolling a pair of
dice. The dice roll should randomly display numbers from 1 to 6 each time the user
clicks a button. The program should show the results for both dice and allow repeated
rolls.

Apparatus/Software Required:
● A computer with Python 3 installed.
● Python libraries: tkinter (for GUI) and random (for generating random
numbers).
● Python IDE (like PyCharm, Jupyter Notebook, or any text editor with Python
support).

Algorithm:
1. Import Required Libraries:
○ Import tkinter for creating the GUI.
○ Import random for generating random numbers.
2. Create the Main Application Window:
○ Initialize the main window.
○ Set window title and size.
3. Design the Display Area for Dice:
○ Use Labels to show the result of each dice roll.
4. Create a Button to Roll the Dice:
○ Define a button that triggers the dice roll.
5. Define a Function to Roll Dice:
○ Generate two random numbers between 1 and 6.
○ Display the random numbers on the dice display area.
6. Run the Application Loop:
○ Start the main event loop to make the dice roll simulator interactive.

By: Prof. Ganesh S. Wayal


Flowchart:

Source Code:

Sample Input and Output:


● GUI Dice Roll Simulator Interaction:
○ User clicks on the “Roll Dice” button.
○ The numbers displayed on the dice labels update to show the result of
each roll.
● For example:
○ The user clicks "Roll Dice" and the labels display 4 and 2, indicating
one die rolled a 4 and the other rolled a 2.

Observations:
1. Each click on the "Roll Dice" button generates a new pair of random numbers.
2. The simulator correctly displays the outcome of the dice rolls.
3. The GUI is interactive and allows continuous rolling of dice.

Conclusion:
The program successfully simulates a dice roll using Python’s tkinter and
random libraries, providing a simple and effective interactive GUI. This project
demonstrates basic GUI programming and random number generation in Python.

By: Prof. Ganesh S. Wayal


Mini Project - c: Tic Tac Toe Game
Objective:
To develop a Python program that simulates a two-player Tic Tac Toe game with a
Graphical User Interface (GUI). The game should allow players to take turns marking
spaces in a 3x3 grid, and it should determine and display the winner or announce a
draw if applicable.

Problem Statement:
Create a Python program with a GUI to simulate the classic Tic Tac Toe game. The
game should:

1. Allow two players to take turns placing their marks (X and O) on a 3x3 grid.
2. Detect if a player has won by aligning three of their marks horizontally,
vertically, or diagonally.
3. Announce the winner or declare a draw if all spaces are filled without a
winner.

Apparatus/Software Required:
● A computer with Python 3 installed.
● Python libraries: tkinter for creating the GUI.
● Python IDE (like PyCharm, Jupyter Notebook, or any text editor with Python
support).

Algorithm:
1. Import Required Libraries:
○ Import tkinter for GUI creation.
2. Initialize Main Application Window:
○ Set up the main window with a title and dimensions.
3. Create a 3x3 Grid of Buttons:
○ Use Button widgets for each cell in the Tic Tac Toe grid.
○ Arrange buttons in a 3x3 grid layout.
4. Define Game Logic:
○ Use a 2D list to represent the board state.
○ Define a function to handle button clicks, updating the board with the
current player’s mark (X or O).
○ Alternate turns between Player X and Player O after each click.
5. Check for Win or Draw:

By: Prof. Ganesh S. Wayal


○ After each turn, check if there is a win by verifying if any row, column,
or diagonal has the same mark.
○ If there is a win, display a message declaring the winner and reset the
game.
○ If all spaces are filled and no winner is found, declare a draw and reset
the game.
6. Run the Application Loop:
○ Start the main event loop to make the Tic Tac Toe game interactive.

Flowchart:

Source Code:

Sample Input and Output:


● Game Interaction:
○ Players take turns clicking on cells in the grid.
○ The board updates to show each player’s mark (X or O).
○ After each move, the game checks for a winner or a draw.
○ When there is a winner or a draw, a message is displayed, and the
game resets.

Observations:
1. The game alternates turns between Player X and Player O.
2. The program correctly detects wins across rows, columns, and diagonals.
3. A message box displays the result, either announcing the winner or declaring a
draw.

Conclusion:
The program successfully implements a Tic Tac Toe game with a GUI, allowing two
players to play interactively. It demonstrates effective use of GUI programming and
basic game logic with win and draw conditions.

By: Prof. Ganesh S. Wayal

You might also like