Python Work Book
Python Work Book
STUDENT NAME :
REGISTER NO :
CLASS / SECTION :
DEPARTMENT :
YEAR / SEMESTER : I/ II
LABORATORY
241GES214L PROBLEM SOLVING USING PYTHON
LABORATORY
(COMMON TO ALL BRANCHES)
LTPR
0 31 2
COURSE OBJECTIVES:
LIST OF EXPERIMENTS:
1. Identification and solving of simple real life or scientific or technical problems, and
developing flow charts for the same. (Electricity Billing, Retail shop billing, Sin series, weight of a
motorbike, Weight of a steel bar, compute Electrical Current in Three Phase AC Circuit, etc.)
2. Python programming using simple statements and expressions (exchange the values of
two variables, circulate the values of n variables, distance between two points).
3. Scientific problems using Conditionals and Iterative loops. (Number series, Number Patterns, pyramid
pattern)
4. Implementing real-time/technical applications using Lists, Tuples. (Items present
in a library/Components of a car/ Materials required for construction of a building –operations of list
& tuples)
5. Implementing real-time/technical applications using Sets, Dictionaries. (Language, components of an
automobile, Elements of a civil structure, etc.- operations of Sets & Dictionaries)
6. Implementing programs using Functions. (Factorial, largest number in a list, area of shape)
7. Implementing programs using Strings. (reverse, palindrome, character count, replacing characters)
8. Implementing programs using written modules and Python Standard Libraries (pandas, numpy.
Matplotlib, scipy)
9. Implementing real-time/technical applications using File handling. (copy from one file to another, word
count, longest word)
10. Implementing real-time/technical applications using Exception handling. (divide by zero error, voter‟s age
validity, student mark range validation)
11. Exploring Pygame tool.
12. Developing a game activity using Pygame like bouncing ball, car race etc.
TOTAL :60 PERIODS
COURSE OUTCOMES:
TEXT BOOKS:
1. Allen B. Downey, “Think Python: How to Think like a Computer Scientist”, 2nd Edition,
O‟Reilly Publishers, 2016.
2. Karl Beecher, “Computational Thinking: A Beginner's Guide to Problem Solving and Programming”,
1st Edition, BCS Learning & Development Limited, 2017.
REFERENCES:
1. Paul Deitel and Harvey Deitel, “Python for Programmers”, Pearson Education, 1st Edition, 2021.
2. G Venkatesh and Madhavan Mukund, “Computational Thinking: A Primer for Programmers and Data
Scientists”, 1st Edition, Notion Press, 2021.
3. John V Guttag, "Introduction to Computation and Programming Using Python: With Applications
to Computational Modeling and Understanding Data”, Third Edition, MIT Press, 2021.
4. Eric Matthes, “Python Crash Course, A Hands - on Project Based Introduction to Programming”,
2nd Edition, No Starch Press, 2019.
5. [Link]
6. Martin C. Brown, “Python: The Complete Reference”, 4th Edition, Mc-Graw Hill, 2018.
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
1 3 3 3 3 2 - - - - - 2 2 3 - 3
2 3 3 3 3 2 - - - - - 2 2 3 - -
3 3 3 3 3 2 - - - - - 2 - 3 - -
4 2 2 - 2 2 - - - - - 1 - 3 - -
5 1 2 - - 1 - - - - - 1 - 2 - -
AVG 2 3 3 3 2 - - - - - 2 2 3 3 -
CONTENTS
Ex. Page
Date Name of the Experiment Marks Staff sign
No No
[Link] AND SOLVING OF SIMPLE REAL LIFE OR SCIENTIFIC OR TECHNICAL
PROBLEMS, AND DEVELOPING FLOW CHARTS
1.a Electricity Billing
1.b Retail shop billing
1.c Sin Series
1.d Weight of a motorbike
1.e Weight of a steel bar
1.f Compute Electrical Current in Three Phase AC
Circuit
[Link] PROGRAMMING USING SIMPLE STATEMENTS AND EXPRESSIONS
2.a Exchange the values of two variables
2.b Circulate the values of n variables
2.c Distance between two points
[Link] PROBLEMS USING CONDITIONALS AND ITERATIVE LOOPS
3.a Number series(Fibonacci Series)
3.b Number Patterns
3.c Pyramid pattern
4. IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS USING LISTS, TUPLES
4.a To check book items present in the Library
4.b To know about the components of a car
5. IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS USING SETS, DICTIONARIES
5.a Languages spoken state wise
5.b Dictionary Operations
6. IMPLEMENTING PROGRAMS USING FUNCTIONS
6.a Factorial of a number
6.b To find largest number in a given list using
functions
6.c To find area of a different shapes using functions
[Link] PROGRAMS USING STRING
7.a To reverse a given string
7.b To check for Palindrome
7.c To count number of characters and words in a
given string
7.d Replacing characters
[Link] PROGRAMS USING WRITTEN MODULES AND PYTHON STANDARD
LIBRARIES
8.a (i) Using pandas module with series
(ii) Using pandas module with data frame
8.b (i) Using numpy module (Matrix Addition)
(ii) Using numpy module (Matrix Multiplication)
8.c Using matplotlib module
8.d Using scipy Module
[Link] REAL-TIME/TECHNICAL APPLICATIONS USING FILE HANDLING
9.a Copy from one file to another
9.b To count number of words in the given file
9.c To find the longest word in the given sentence
10. IMPLEMENTING REALTIME/TECHNICAL APPLICATIONS USING EXCEPTIONHANDLING
10.a Using Exception: Divide by zero error
10.b Voter’s age validity using exception handling
10.c Student mark range validation
[Link] PYGAME TOOL
11.a Simulation of Elliptical Orbit
[Link] A GAME ACTIVITY USING PYGAME
12.a Simulation of Bouncing Ball
12.b Simulation of Car racing game
[Link] BEYOND SYLLBUS
13.a Student Result Management System Using
Class and Object
13.b Library Management System Using OOPS
13.c Online Shopping Cart Using OOPS
13.d ATM Transaction System Using OOPS
1. Identification and solving of simple real life or scientific or technical problems,
and developing flow charts
[Link].1 A
Electricity Billing
DATE:
Objective:
To write and execute a Python program that calculates the electricity bill based on the number of units
consumed using conditional statements.
Pre-requisite Knowledge:
Basic knowledge of Python
Understanding of variables and data types
Knowledge of conditional statements (if, elif, else)Basic input and output operations
Problem Statement:
Write a Python program to calculate the electricity bill for a consumer based on the number of units
consumed.
The billing criteria is as follows:
For first 100 units: ₹1.5 per unit
For next 100 units: ₹2.5 per unit
For units above 200: ₹4 per unit
Algorithm :
1. Start the program.
2. Read the number of units consumed.
3. If units ≤ 100, calculate bill = units × 1.5
4. Else if units ≤ 200, calculate bill =
o (100 × 1.5) + (units − 100) × 2.5
5. Else, calculate bill =
o (100 × 1.5) + (100 × 2.5) + (units − 200) × 4
6. Display the total electricity bill.
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter number of units consumed: 250
Sample Output:
Total Electricity Bill = ₹725.0
Result:
Thus, the Python program to calculate the electricity bill using conditional statements was successfully
executed and the correct output was obtained.
Viva Questions:
1. What is an algorithm?
2. What are conditional statements in Python?
3. What is the use of if-elif-else?
4. What data type is used to store decimal values in Python?
5. How do you take input from the user in Python?
6. What is the difference between = and ==?
7. Why is Python called an interpreted language?
Grade / Mark:
Staff Signature:
1. Identification and solving of simple real life or scientific or technical problems,
and developing flow charts
[Link].1 B
Retail Shop Billing
DATE:
Objective:
To develop and execute a Python program that calculates the total bill amount in a retail shop based on
the quantity of items purchased and their prices.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of variables and data types
Understanding of input and output statements
Basic arithmetic operations
Problem Statement:
Write a Python program to generate a retail shop bill by accepting the item name, price per item, and
quantity purchased. Calculate the total cost and display the final bill amount.
Algorithm :
1. Start the program.
2. Read the item name.
3. Read the price of the item.
4. Read the quantity purchased.
5. Calculate the total bill using the formula:
o Total Bill = Price × Quantity
6. Display the item details and total bill amount.
7. Stop the program.
Logic:
Flowchart
Sample Input / Output:
Sample Input:
Enter item name: Pen
Enter price per item: 10
Enter quantity: 15
Sample Output:
Item Name: Pen
Price per Item: ₹10
Quantity: 15
Total Bill Amount: ₹150
Result:
Thus, the Python program to calculate the retail shop bill was successfully executed and the correct bill
amount was displayed.
Viva Questions:
1. What is a variable in Python?
2. What data type is used to store price values?
3. How do you take input from the user in Python?
4. What arithmetic operators are used in Python?
5. What is the use of the print() function?
6. What is an IDE?
7. What is Python?
Grade / Mark:
Staff Signature:
1. Identification and solving of simple real life or scientific or technical problems,
and developing flow charts
[Link].1 C
Sin Series
DATE:
Objective:
To write and execute a Python program to calculate the value of sin(x) using its Taylor series expansion.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of loops (for loop)
Understanding of functions
Basic mathematical concepts
Factorial calculation
Problem Statement:
Write a Python program to find the value of sin(x) using the Taylor series expansion for a given angle
(in radians) and number of terms.
The Taylor series expansion of sin(x) is:
sin(x)=x−x33!+x55!−x77!+…\sin(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} +
\dotssin(x)=x−3!x3+5!x5−7!x7+…
Algorithm :
1. Start the program.
2. Read the value of x (in radians).
3. Read the number of terms n.
4. Initialize sinx = 0.
5. For each term from 0 to n-1:
o Calculate the term using
(−1)i×x2i+1(2i+1)!(-1)^i \times \frac{x^{2i+1}}{(2i+1)!}(−1)i×(2i+1)!x2i+1
o Add the term to sinx.
6. Display the final value of sin(x).
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter the value of x (in radians): 1
Enter number of terms: 5
Sample Output:
Value of sin(x) using series = 0.84147
Result:
Thus, the Python program to compute the value of sin(x) using Taylor series expansion was successfully
executed and the correct result was obtained.
Viva Questions:
1. What is a Taylor series?
2. Why is factorial used in the sin series?
3. What is the use of loops in this program?
4. What data type is used to store decimal values?
5. Why is the angle taken in radians?
6. What is the purpose of (-1)^i in the series?
7. What is the use of a function in Python?
Grade / Mark:
Staff Signature
1. Identification and solving of simple real life or scientific or technical problems,
and developing flow charts
[Link].1 D
Weight of a Motorbike
DATE:
Objective:
To write and execute a Python program to calculate the total weight of a motorbike based on the weight
of its components.
Pre-requisite Knowledge:
Basic knowledge of Python
Understanding of variables and data types
Knowledge of input and output statements
Basic arithmetic operations
Problem Statement:
Write a Python program to calculate the total weight of a motorbike by accepting the weight of its main
components such as engine, frame, fuel tank, and wheels.
Algorithm :
1. Start the program.
2. Read the weight of the engine.
3. Read the weight of the frame.
4. Read the weight of the fuel tank.
5. Read the weight of the wheels.
6. Calculate total weight using the formula:
o Total Weight = Engine + Frame + Fuel Tank + Wheels
7. Display the total weight of the motorbike.
8. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter engine weight (kg): 60
Enter frame weight (kg): 45
Enter fuel tank weight (kg): 12
Enter wheels weight (kg): 28
Sample Output:
Total Weight of the Motorbike = 145 kg
Result:
Thus, the Python program to calculate the total weight of a motorbike was successfully executed and the
correct total weight was obtained.
Viva Questions:
1. What is a variable in Python?
2. What data type is used to store weight values?
3. What arithmetic operators are used in Python?
4. How do you take input from the user in Python?
5. What is the use of the print() function?
6. Why is Python suitable for simple calculations?
7. What is an IDE?
Grade / Mark:
Staff Signature
1. Identification and solving of simple real life or scientific or technical problems,
and developing flow charts
[Link].1 E
Weight of a Steel Bar
DATE:
Objective:
To write and execute a Python program to calculate the weight of a steel bar using its dimensions and
density.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of variables and data types
Understanding of input and output statements
Basic arithmetic and formula application
Problem Statement:
Write a Python program to calculate the weight of a steel bar by accepting its length, width, height, and
density of steel.
Algorithm :
1. Start the program.
2. Read the length of the steel bar.
3. Read the width of the steel bar.
4. Read the height of the steel bar.
5. Read the density of steel.
6. Calculate volume using the formula:
o Volume = Length × Width × Height
7. Calculate weight using the formula:
o Weight = Volume × Density
8. Display the weight of the steel bar.
9. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter length (m): 2
Enter width (m): 0.05
Enter height (m): 0.05
Enter density (kg/m³): 7850
Sample Output:
Weight of the Steel Bar = 39.25 kg
Result:
Thus, the Python program to calculate the weight of a steel bar was successfully executed and the
correct result was obtained.
Viva Questions:
1. What is density?
2. What is the formula for volume of a rectangular bar?
3. Why is density required to calculate weight?
4. What data type is used for decimal values in Python?
5. What are input and output statements?
6. What arithmetic operators are used in Python?
7. What is Python?
Grade / Mark:
Staff Signature
1. Identification and solving of simple real life or scientific or technical problems,
and developing flow charts
[Link].1 F
Compute Electrical Current in Three Phase AC Circuit
DATE:
Objective:
To write and execute a Python program to compute the line current in a three-phase AC circuit using the
given power, voltage, and power factor.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of variables and data types
Understanding of input and output statements
Basic electrical concepts (power, voltage, current)
Problem Statement:
Write a Python program to compute the line current in a three-phase AC circuit when the total power,
line voltage, and power factor are given.
The formula for three-phase power is:
P=3×V×I×cosϕP = \sqrt{3} \times V \times I \times \cos\phiP=3×V×I×cosϕ
Where:
PPP = Total power (watts)
VVV = Line voltage (volts)
III = Line current (amperes)
cosϕ\cos\phicosϕ = Power factor
Algorithm :
1. Start the program.
2. Read the total power PPP.
3. Read the line voltage VVV.
4. Read the power factor cosϕ\cos\phicosϕ.
5. Calculate the line current using:
I=P3×V×cosϕI = \frac{P}{\sqrt{3} \times V \times \cos\phi}I=3×V×cosϕP
6. Display the value of line current.
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter total power (W): 10000
Enter line voltage (V): 415
Enter power factor: 0.8
Sample Output:
Line Current = 17.38 A
Result:
Thus, the Python program to compute the electrical current in a three-phase AC circuit was successfully
executed and the correct line current was obtained.
Viva Questions:
1. What is a three-phase AC system?
2. What is power factor?
3. Why is √3 used in the three-phase power formula?
4. What is line voltage?
5. What is line current?
6. What are the advantages of three-phase systems?
7. What data type is used for electrical calculations in Python?
Grade / Mark:
Staff Signature
2. Python programming using simple statements and expressions
[Link].2 A
Exchange the Values of Two Variables
DATE:
Objective:
To write and execute a Python program to exchange (swap) the values of two variables.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of variables and data types
Understanding of input and output statements
Problem Statement:
Write a Python program to exchange the values of two variables entered by the user.
Algorithm :
1. Start the program.
2. Read the value of variable a.
3. Read the value of variable b.
4. Exchange the values of a and b using a temporary variable or Python’s swapping method.
5. Display the values after swapping.
6. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter value of a: 10
Enter value of b: 20
Sample Output:
After swapping:
a = 20
b = 10
Result:
Thus, the Python program to exchange the values of two variables was successfully executed and the
values were swapped correctly.
Viva Questions:
1. What is a variable in Python?
2. What is swapping?
3. How is swapping done in Python without a temporary variable?
4. What data types can be swapped in Python?
5. What is the use of assignment operator?
6. What is multiple assignment in Python?
7. Why is Python swapping easier compared to other languages?
Grade / Mark:
Staff Signature
2. Python programming using simple statements and expressions
[Link].2 B
Circulate the Values of n Variables
DATE:
Objective:
To write and execute a Python program to circulate (rotate) the values of n variables either to the left or
right.
Pre-requisite Knowledge:
Basics of Python programming
Understanding of lists and loops
Knowledge of input and output statements
Basic arithmetic and indexing
Problem Statement:
Write a Python program to circulate the values of n variables entered by the user.
Left circulation: Each element moves one position to the left, the first element moves to the
last.
Right circulation: Each element moves one position to the right, the last element moves to the
first.
Algorithm :
1. Start the program.
2. Read the number of variables n.
3. Read the values of the n variables and store in a list.
4. Ask the user for the type of circulation (left or right).
5. Perform circulation:
o Left circulation: Remove the first element and append it at the end.
o Right circulation: Remove the last element and insert it at the beginning.
6. Display the circulated values.
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input (Left Circulation):
Enter number of variables: 5
Enter values: 10 20 30 40 50
Enter circulation type (left/right): left
Sample Output:
Values after left circulation: 20 30 40 50 10
Sample Input (Right Circulation):
Enter circulation type (left/right): right
Sample Output:
Values after right circulation: 50 10 20 30 40
Result:
Thus, the Python program to circulate the values of n variables was successfully executed and the
values were rotated correctly as per user selection.
Viva Questions:
1. What is circulation (rotation) of variables?
2. How are lists used in Python?
3. How do you perform left and right circulation?
4. Can this program be done without using a list?
5. What is indexing in Python?
6. How do loops help in circulation?
7. How can multiple rotations be done efficiently?
Grade / Mark:
Staff Signature
2. Python programming using simple statements and expressions
[Link].2 C
DATE: Distance Between Two Points
Objective:
To write and execute a Python program to calculate the distance between two points in a 2D plane using
their coordinates.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of variables and data types
Understanding of input and output statements
Basic mathematical operations (addition, subtraction, square, square root)
Problem Statement:
Write a Python program to find the distance between two points (x1,y1)(x_1, y_1)(x1,y1) and
(x2,y2)(x_2, y_2)(x2,y2) using the formula:
Distance=(x2−x1)2+(y2−y1)2\text{Distance} = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}Distance=(x2−x1
)2+(y2−y1)2
Algorithm :
1. Start the program.
2. Read coordinates x1,y1x_1, y_1x1,y1 of the first point.
3. Read coordinates x2,y2x_2, y_2x2,y2 of the second point.
4. Calculate the difference in x and y coordinates:
o dx = x2 − x1
o dy = y2 − y1
5. Calculate distance using the formula:
Distance=dx2+dy2\text{Distance} = \sqrt{dx^2 + dy^2}Distance=dx2+dy2
6. Display the distance.
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter x1: 3
Enter y1: 4
Enter x2: 7
Enter y2: 1
Sample Output:
Distance between the points = 5.0
Result:
Thus, the Python program to calculate the distance between two points in a 2D plane was successfully
executed and the correct distance was obtained.
Viva Questions:
1. What is the distance formula in 2D?
2. What are coordinates of a point?
3. What data type is used to store decimal numbers in Python?
4. How do you calculate square root in Python?
5. Can this program be extended to 3D points?
6. What is the difference between absolute distance and vector?
7. What is the use of math module in Python?
Grade / Mark:
Staff Signature
3. Scientific problems using Conditionals and Iterative loops
[Link].3 A
Number Series (Fibonacci Series)
DATE:
Objective:
To write and execute a Python program to generate the Fibonacci series up to a given number of terms.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of loops (for or while)
Understanding of variables and data types
Input and output statements
Problem Statement:
Write a Python program to generate the Fibonacci series of n terms.
The Fibonacci series is defined as:
0,1,1,2,3,5,8,13,21,…0, 1, 1, 2, 3, 5, 8, 13, 21, \dots0,1,1,2,3,5,8,13,21,…
Where each term is the sum of the two preceding terms:
F(n)=F(n−1)+F(n−2),F(0)=0,F(1)=1F(n) = F(n-1) + F(n-2), \quad F(0)=0,
F(1)=1F(n)=F(n−1)+F(n−2),F(0)=0,F(1)=1
Algorithm :
1. Start the program.
2. Read the number of terms n.
3. Initialize the first two terms: a = 0, b = 1.
4. Print a and b.
5. For i from 3 to n:
o Calculate next term c = a + b.
o Print c.
o Update a = b, b = c.
6. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter number of terms: 8
Sample Output:
Fibonacci Series: 0 1 1 2 3 5 8 13
Result:
Thus, the Python program to generate the Fibonacci series up to n terms was successfully executed and
the correct series was displayed.
Viva Questions:
1. What is the Fibonacci series?
2. What are the first two terms of the Fibonacci series?
3. How is each term in the series calculated?
4. Can Fibonacci series be generated using recursion?
5. What data type is suitable for storing Fibonacci numbers?
6. How can the program be modified to generate series up to a given number instead of terms?
7. What is the difference between iterative and recursive methods?
Grade / Mark:
Staff Signature
3. Scientific problems using Conditionals and Iterative loops
[Link].3 B
Number Patterns
DATE:
Objective:
To write and execute a Python program to display different types of number patterns.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of loops (for or while)
Understanding of variables and data types
Input and output statements
Problem Statement:
Write a Python program to display number patterns using loops.
Example Pattern 1: Right-angled Triangle
1
12
123
1234
12345
Example Pattern 2: Inverted Triangle
12345
1234
123
12
1
Algorithm :
1. Start the program.
2. Read the number of rows n.
3. For right-angled triangle pattern:
o Loop i from 1 to n
Loop j from 1 to i
Print j without newline
Print newline
4. For inverted triangle pattern:
o Loop i from n to 1
Loop j from 1 to i
Print j without newline
Print newline
5. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter number of rows: 5
Sample Output (Right-angled Triangle):
1
12
123
1234
12345
Sample Output (Inverted Triangle):
12345
1234
123
12
1
Result:
Thus, the Python program to display number patterns using loops was successfully executed and the
correct patterns were displayed.
Viva Questions:
1. What is a number pattern?
2. How do nested loops work in Python?
3. How can you print numbers without a newline?
4. Can spaces be added to form pyramid patterns?
5. What is the difference between print() and print(end="")?
6. How do you generate a mirrored pattern?
7. Can patterns be generated using functions in Python?
Grade / Mark:
Staff Signature
3. Scientific problems using Conditionals and Iterative loops
[Link].3 C
Pyramid Pattern
DATE:
Objective:
To write and execute a Python program to display a pyramid pattern of numbers or stars using nested
loops.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of loops (for or while)
Understanding of variables and data types
Input and output statements
Problem Statement:
Write a Python program to display a pyramid pattern.
Example: Pyramid of Stars
*
***
*****
*******
*********
Example: Pyramid of Numbers
1
123
12345
1234567
123456789
Algorithm :
1. Start the program.
2. Read the number of rows n.
3. For each row i from 1 to n:
o Print spaces: n - i
o Print stars or numbers: 2*i - 1
o Move to the next line
4. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter number of rows: 5
Sample Output (Stars):
*
***
*****
*******
*********
Sample Output (Numbers):
1
123
12345
1234567
123456789
Result:
Thus, the Python program to display a pyramid pattern using nested loops was successfully executed
and the correct pyramid pattern was displayed.
Viva Questions:
1. What is a pyramid pattern?
2. How do nested loops work to create pyramid patterns?
3. How do you control spaces in a pyramid pattern?
4. How is the number of stars calculated for each row?
5. Can a pyramid pattern be inverted?
6. Can patterns be generated using functions in Python?
7. How can you print numbers instead of stars in a pyramid?
Grade / Mark:
Staff Signature
4. Implementing real-time/technical applications using Lists, Tuples
[Link].4 A
Check Book Items Present in the Library
DATE:
Objective:
To write and execute a Python program to check whether a book is available in the library from a list of
books.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of lists and loops
Understanding of input and output statements
Conditional statements (if, else)
Problem Statement:
Write a Python program to check whether a particular book is present in the library. The program should
accept a book name from the user and search for it in the library database (a list of books).
Algorithm :
1. Start the program.
2. Create a list of books available in the library.
3. Read the name of the book to search from the user.
4. Check if the book exists in the list:
o If yes, display “Book is available in the library.”
o If no, display “Book is not available in the library.”
5. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter the book name to search: Python Programming
Sample Output (If Available):
Book "Python Programming" is available in the library.
Sample Output (If Not Available):
Book "Python Programming" is not available in the library.
Result:
Thus, the Python program to check the availability of a book in the library was successfully executed
and the correct result was displayed.
Viva Questions:
1. How is a list defined in Python?
2. What are the different methods to search for an item in a list?
3. What is the difference between in and not in operators?
4. How can the program be modified to display all available books starting with a certain letter?
5. What data type is suitable for storing book names?
6. Can we make the search case-insensitive? How?
7. What is the use of conditional statements in this program?
Grade / Mark:
Staff Signature
4. Implementing real-time/technical applications using Lists, Tuples
[Link].4 B
To Know About the Components of a Car
DATE:
Objective:
To create a Python program that displays information about various components of a car and their
functions.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of lists or dictionaries
Understanding of input and output statements
Conditional statements (if, elif, else)
Problem Statement:
Write a Python program to provide information about the components of a car. The program should
accept the name of a car component from the user and display its function or description.
Example Components:
Engine
Transmission
Brakes
Suspension
Steering
Wheels
Battery
Algorithm :
1. Start the program.
2. Create a dictionary with car components as keys and their functions as values.
3. Read the component name from the user.
4. Check if the component exists in the dictionary:
o If yes, display the function of the component.
o If no, display “Component not found.”
5. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter car component: Engine
Sample Output:
Engine: Converts fuel into mechanical energy to move the car.
Sample Input:
Enter car component: Clutch
Sample Output:
Clutch: Component not found in the database.
Result:
Thus, the Python program to display information about the components of a car was successfully
executed and provided correct details for the selected component.
Viva Questions:
1. What are the main components of a car?
2. What is the function of the engine?
3. What is the purpose of the transmission system?
4. How do brakes work in a car?
5. What is the function of suspension and steering?
6. What data structures in Python are suitable for storing components and their descriptions?
7. How can this program be modified to display all components at once?
Grade / Mark:
Staff Signature
5. Implementing real-time/technical applications using Sets, Dictionaries
[Link].5 A
Languages Spoken State-wise
DATE:
Objective:
To create a Python program that displays the languages spoken in different states of a country.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of dictionaries and lists
Understanding of input and output statements
Conditional statements (if, elif, else)
Problem Statement:
Write a Python program to display the languages spoken in different states. The program should accept
the name of a state from the user and display the language(s) spoken in that state.
Example States and Languages:
Maharashtra → Marathi
Tamil Nadu → Tamil
Kerala → Malayalam
Karnataka → Kannada
West Bengal → Bengali
Algorithm :
1. Start the program.
2. Create a dictionary with states as keys and languages as values.
3. Read the name of the state from the user.
4. Check if the state exists in the dictionary:
o If yes, display the language(s) spoken in the state.
o If no, display “State not found.”
5. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter state name: Kerala
Sample Output:
Language spoken in Kerala: Malayalam
Sample Input:
Enter state name: Goa
Sample Output:
State not found in the database.
Result:
Thus, the Python program to display languages spoken in different states was successfully executed and
provided correct information for the selected state.
Viva Questions:
1. What data structure is used to store states and languages in Python?
2. How can multiple languages be stored for a single state?
3. What is the difference between a list and a dictionary in Python?
4. How can the program handle case-insensitive input?
5. Can this program display all states and their languages at once?
6. How do you check if a key exists in a dictionary?
7. What are some other ways to organize country/state language data in Python?
Grade / Mark:
Staff Signature
5. Implementing real-time/technical applications using Sets, Dictionaries
[Link].5 B
Dictionary Operations
DATE:
Objective:
To write and execute a Python program to perform basic operations on a dictionary such as adding,
updating, deleting, and accessing items.
Pre-requisite Knowledge:
Basics of Python programming
Understanding of dictionaries in Python
Knowledge of input and output statements
Conditional statements (if, elif, else)
Problem Statement:
Write a Python program to perform operations on a dictionary including:
1. Creating a dictionary
2. Adding a new item
3. Updating an existing item
4. Deleting an item
5. Accessing an item
6. Displaying all keys and values
Algorithm :
1. Start the program.
2. Create a dictionary with some initial items.
3. Perform the following operations:
o Add an item: Use dict[key] = value
o Update an item: Use dict[key] = new_value
o Delete an item: Use del dict[key] or pop()
o Access an item: Use dict[key]
o Display all keys: Use [Link]()
o Display all values: Use [Link]()
4. Display the dictionary after each operation.
5. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Initial Dictionary: {'a': 10, 'b': 20, 'c': 30}
Add item: 'd': 40
Update item: 'b': 25
Delete item: 'c'
Access item: 'a'
Sample Output:
Initial Dictionary: {'a': 10, 'b': 20, 'c': 30}
After adding item: {'a': 10, 'b': 20, 'c': 30, 'd': 40}
After updating item: {'a': 10, 'b': 25, 'c': 30, 'd': 40}
After deleting item: {'a': 10, 'b': 25, 'd': 40}
Accessed item 'a': 10
All Keys: dict_keys(['a', 'b', 'd'])
All Values: dict_values([10, 25, 40])
Result:
Thus, the Python program to perform dictionary operations was successfully executed and all operations
such as addition, update, deletion, and access were performed correctly.
Viva Questions:
1. What is a dictionary in Python?
2. How do you add a new key-value pair in a dictionary?
3. How do you update an existing item?
4. How do you delete an item from a dictionary?
5. How do you access a value using a key?
6. What methods can be used to get all keys or all values?
7. What is the difference between a dictionary and a list?
Grade / Mark:
Staff Signature
6. Implementing programs using Functions
[Link].6 A
Factorial of a Number
DATE:
Ex. 16.
Objective:
To write and execute a Python program to calculate the factorial of a given number using iterative or
recursive method.
Pre-requisite Knowledge:
Basics of Python programming
Understanding of loops (for or while)
Understanding of functions (for recursion)
Input and output statements
Problem Statement:
Write a Python program to calculate the factorial of a given number n.
Factorial of n is defined as:
n!=n×(n−1)×(n−2)×⋯×1n! = n \times (n-1) \times (n-2) \times \dots \times 1n!=n×(n−1)×(n−2)×⋯×1
For n = 0, 0! = 1.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter a number: 5
Sample Output:
Factorial of 5 = 120
Result:
Thus, the Python program to calculate the factorial of a number was successfully executed and the
correct factorial value was obtained.
Viva Questions:
1. What is factorial of a number?
2. What is the factorial of 0?
3. How can factorial be calculated using loops?
4. How can factorial be calculated using recursion?
5. What data type is suitable for storing factorial values?
6. Can factorial be negative? Why or why not?
7. What is the difference between iterative and recursive methods?
Grade / Mark:
Staff Signature
6. Implementing programs using Functions
[Link].6 B
To Find Largest Number in a Given List Using Functions
DATE:
Objective:
To write and execute a Python program to find the largest number in a list using a user-defined function.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of functions in Python
Understanding of lists and loops
Input and output statements
Problem Statement:
Write a Python program that defines a function to find the largest number in a given list and returns it.
Algorithm :
1. Start the program.
2. Define a function find_largest(lst) that:
o Initializes max_num = lst[0]
o Loops through each element in lst
If element > max_num, update max_num
o Return max_num
3. Read the list of numbers from the user.
4. Call the function find_largest(lst) with the input list.
5. Display the largest number.
6. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter numbers separated by space: 10 25 5 70 30
Sample Output:
The largest number in the list is: 70
Result:
Thus, the Python program to find the largest number in a list using a user-defined function was
successfully executed and returned the correct result.
Viva Questions:
1. What is a function in Python?
2. How is a list defined in Python?
3. How do you find the largest number without using built-in functions?
4. What is the difference between a user-defined function and a built-in function?
5. How can you modify the program to find the smallest number?
6. What data types can be stored in a list?
7. What is the role of the return statement in a function?
Grade / Mark:
Staff Signature
6. Implementing programs using Functions
[Link].6 C
To Find Area of Different Shapes Using Functions
DATE:
Objective:
To write and execute a Python program to calculate the area of different shapes (rectangle, square,
circle, and triangle) using functions.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of functions in Python
Understanding of input and output statements
Basic formulas for area of shapes
Problem Statement:
Write a Python program to calculate the area of different shapes using separate functions for each shape.
The user should be able to choose the shape and provide required dimensions.
Formulas:
Rectangle: Area = length × width
Square: Area = side × side
Circle: Area = π × radius²
Triangle: Area = 0.5 × base × height
Algorithm :
1. Start the program.
2. Define functions for each shape:
o area_rectangle(length, width)
o area_square(side)
o area_circle(radius)
o area_triangle(base, height)
3. Display a menu to the user to choose the shape.
4. Read user choice and required dimensions.
5. Call the appropriate function based on user choice.
6. Display the calculated area.
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Choose shape to calculate area:
1. Rectangle
2. Square
3. Circle
4. Triangle
Enter choice: 1
Enter length: 5
Enter width: 3
Sample Output:
Area of Rectangle = 15
Sample Input (Circle):
Enter radius: 4
Sample Output:
Area of Circle = 50.27
Result:
Thus, the Python program to calculate the area of different shapes using functions was successfully
executed and produced correct results for all selected shapes.
Viva Questions:
1. What is a function in Python?
2. How is a rectangle area calculated?
3. How do you calculate the area of a circle in Python?
4. What is the difference between a function with parameters and without parameters?
5. How can this program be modified to handle multiple calculations?
6. What is the value of π in Python?
7. Can the program be extended to include more shapes?
Grade / Mark:
Staff Signature
7. Implementing programs using Strings
[Link].7 A
To Reverse a Given String
DATE:
Objective:
To write and execute a Python program to reverse a given string entered by the user.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of strings and string operations
Input and output statements
Slicing and loops in Python
Problem Statement:
Write a Python program to reverse a given string. The program should accept a string from the user and
display it in reverse order.
Algorithm :
1. Start the program.
2. Read the string input from the user.
3. Reverse the string using one of the following methods:
o Slicing: reversed_str = original_str[::-1]
o Loop: Iterate from the last character to the first and append to a new string.
o Built-in function: reversed() and join()
4. Display the reversed string.
5. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter a string: Python
Sample Output:
Reversed string: nohtyP
Sample Input:
Enter a string: Hello World
Sample Output:
Reversed string: dlroW olleH
Result:
Thus, the Python program to reverse a given string was successfully executed and displayed the correct
reversed string.
Viva Questions:
1. What is a string in Python?
2. How can you reverse a string using slicing?
3. What is the difference between [::-1] and reversed()?
4. Can you reverse a string using a loop? How?
5. What data type is returned by reversed() function?
6. How can you reverse each word in a string individually?
7. Can this program handle special characters and spaces?
Grade / Mark:
Staff Signature
7. Implementing programs using Strings
[Link].7 B
To Check for Palindrome
DATE:
Objective:
To write and execute a Python program to check whether a given string or number is a palindrome.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of strings and numbers
Input and output statements
Conditional statements (if, else)
String slicing or loops
Problem Statement:
Write a Python program to check whether a given string or number is a palindrome.
Palindrome: A string or number that reads the same forward and backward.
Examples: "radar", "level", 121
Algorithm :
1. Start the program.
2. Read input from the user (string or number).
3. Convert input to string (if number).
4. Reverse the string using slicing or loop.
5. Compare the original and reversed strings:
o If they are the same, it is a palindrome.
o Else, it is not a palindrome.
6. Display the result.
7. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input (String):
Enter a string: level
Sample Output:
The string 'level' is a palindrome.
Sample Input (Number):
Enter a number: 121
Sample Output:
The number 121 is a palindrome.
Sample Input (Non-palindrome):
Enter a string: Python
Sample Output:
The string 'Python' is not a palindrome.
Result:
Thus, the Python program to check for palindrome was successfully executed and correctly identified
palindrome and non-palindrome inputs.
Viva Questions:
1. What is a palindrome?
2. Can a number be a palindrome? Give an example.
3. How do you reverse a string in Python?
4. What data type should be used to store numbers for palindrome checking?
5. Can this program ignore spaces and cases? How?
6. How can you check a palindrome using a loop instead of slicing?
7. What are some real-world examples of palindromes?
Grade / Mark:
Staff Signature
7. Implementing programs using Strings
[Link].7 C
To Count Number of Characters and Words in a Given String
DATE:
Objective:
To write and execute a Python program to count the number of characters and words in a string entered
by the user.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of strings and string operations
Input and output statements
Functions like split() and len()
Problem Statement:
Write a Python program that accepts a string from the user and counts:
1. The total number of characters (including spaces or excluding spaces).
2. The total number of words in the string.
Algorithm :
1. Start the program.
2. Read the string input from the user.
3. Count characters: Use len(string) for total characters including spaces.
4. Count words: Use [Link]() to split the string into words and len() to count the words.
5. Display the total number of characters and words.
6. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter a string: Python programming is fun
Sample Output:
Total number of characters: 25
Total number of words: 4
Sample Input (With extra spaces):
Enter a string: Hello World from Python
Sample Output:
Total number of characters: 24
Total number of words: 4
Result:
Thus, the Python program to count the number of characters and words in a string was successfully
executed and returned correct counts.
Viva Questions:
1. How do you count the number of characters in a string?
2. How do you count the number of words in a string?
3. What does the split() function do in Python?
4. How can you exclude spaces while counting characters?
5. Can this program handle multiple spaces between words?
6. How would you count only alphabetic characters?
7. What is the difference between len(string) and len([Link]())?
Grade / Mark:
Staff Signature
8. Implementing programs using Strings
[Link].8 A
Replacing Characters in a String
DATE:
Objective:
To write and execute a Python program to replace a specific character or substring in a string with
another character or substring.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of strings and string operations
Input and output statements
Understanding of the replace() method
Problem Statement:
Write a Python program to replace all occurrences of a specific character or substring in a string with
another character or substring entered by the user.
Algorithm :
1. Start the program.
2. Read the original string from the user.
3. Read the character/substring to be replaced.
4. Read the new character/substring to replace it with.
5. Use the replace() method:
6. new_string = original_string.replace(old, new)
7. Display the modified string.
8. Stop the program.
Logic:
Flowchart:
Sample Input / Output:
Sample Input:
Enter original string: hello world
Enter character/substring to replace: l
Enter new character/substring: x
Sample Output:
Modified string: hexxo worxd
Sample Input:
Enter original string: Python Programming
Enter character/substring to replace: Python
Enter new character/substring: Java
Sample Output:
Modified string: Java Programming
Result:
Thus, the Python program to replace characters or substrings in a string was successfully executed and
the correct modified string was displayed.
Viva Questions:
1. What is the replace() method in Python?
2. How does replace() handle multiple occurrences?
3. Can you replace a substring with multiple characters?
4. Is the replace() method case-sensitive?
5. How can you replace only the first occurrence of a substring?
6. Can you replace characters using loops instead of replace()?
7. How do you modify a string since strings are immutable in Python?
Grade / Mark:
Staff Signature
8. Implementing programs using written modules and Python Standard Libraries
[Link].8 B
Using Pandas Module with Series
DATE:
Objective:
To create and manipulate a pandas Series and perform basic operations like indexing, slicing,
and statistical computations.
Pre-requisite Knowledge:
Basics of Python programming
Lists in Python
Importing and using Python libraries
Problem Statement:
Write a Python program to create a pandas Series from a list of numbers or strings and perform
basic operations such as:
Accessing elements
Slicing
Finding sum, mean, max, min
Algorithm :
1. Import the pandas library using import pandas as pd.
2. Create a list of values (numbers or strings).
3. Convert the list into a pandas Series: s = [Link](list).
4. Perform operations such as:
o Access single elements: s[0]
o Slicing: s[0:3]
o Sum of elements: [Link]() (if numeric)
o Maximum value: [Link]()
o Minimum value: [Link]()
5. Display the results.
Logic:
Flowchart:
Sample Input / Output:
Result:
The pandas Series was successfully created and basic operations such as indexing, slicing, sum,
maximum, and minimum were performed correctly.
Viva Questions:
1. What is a pandas Series?
2. How is a Series different from a Python list?
3. How do you access elements in a Series?
4. Can a Series store strings as well as numbers?
5. What methods can be used to perform statistical operations on a Series?
6. How do you slice a Series?
7. Can you assign custom indices to a Series? How?
Grade / Mark:
Staff Signature
8. Implementing programs using written modules and Python Standard Libraries
[Link].8 C
Using Pandas Module with Data Frame
DATE:
Objective:
To create and manipulate a pandas Data Frame and perform basic operations like selecting
rows/columns, displaying summary statistics, and accessing specific data.
Pre-requisite Knowledge:
Basics of Python programming
Lists and dictionaries in Python
Importing and using Python libraries
Problem Statement:
Write a Python program to create a pandas DataFrame from a dictionary and perform basic
operations such as:
Displaying the DataFrame
Accessing specific columns or rows
Performing statistical operations (mean, max, min)
Describing the DataFrame
Algorithm :
1. Import the pandas library using import pandas as pd.
2. Create a dictionary with keys as column names and values as lists of data.
3. Convert the dictionary to a DataFrame: df = [Link](data).
4. Perform operations such as:
o Display the DataFrame: print(df)
o Access specific columns: df['ColumnName']
o Access specific rows: [Link][row_index] or [Link][row_index]
o Summary statistics: [Link]()
o Maximum/Minimum of a column: df['ColumnName'].max() / df['ColumnName'].min()
5. Display the results.
Logic:
Flowchart:
Sample Input / Output:
Data Frame:
Name Age Marks
0 Alice 20 85
1 Bob 25 90
2 Charlie 23 88
3 David 22 92
Summary Statistics:
Age Marks
count 4.000000 4.000000
mean 22.500000 88.750000
std 2.081666 3.304038
min 20.000000 85.000000
25% 21.250000 86.500000
50% 22.500000 89.000000
75% 23.750000 90.500000
max 25.000000 92.000000
Result:
The pandas DataFrame was successfully created, and operations such as accessing columns and
rows, finding max/min, and displaying summary statistics were performed correctly.
Viva Questions:
1. What is a pandas DataFrame?
2. How is a DataFrame different from a Series?
3. How do you access a specific column or row in a DataFrame?
4. How can you get summary statistics of a DataFrame?
5. Can DataFrames store different data types in different columns?
6. How do you add a new column to a DataFrame?
7. How do you select rows based on a condition?
Grade / Mark:
Staff Signature
8. Implementing programs using written modules and Python Standard Libraries
[Link]. 8E
Using NumPy Module (Matrix Addition)
DATE:
Objective:
To perform addition of two matrices using the NumPy library in Python.
Pre-requisite Knowledge:
Basics of Python programming
Understanding of lists and arrays
Understanding of matrices and matrix operations
Problem Statement:
Write a Python program to add two matrices of the same size using NumPy.
Algorithm :
1. Import the numpy library as np.
2. Create two matrices using [Link]().
3. Add the matrices using either:
o C = A + B or
o C = [Link](A, B)
4. Display the resultant matrix.
Logic:
Flowchart:
Sample Input / Output:
Matrix A:
[[1 2]
[3 4]]
Matrix B:
[[5 6]
[7 8]]
Resultant Matrix after Addition:
[[ 6 8]
[10 12]]
Result:
The Python program successfully added two matrices using NumPy and displayed the correct
resultant matrix.
Viva Questions:
1. What is a NumPy array?
2. How is a NumPy array different from a Python list?
3. How do you perform matrix addition in NumPy?
4. Can matrices of different sizes be added? Why or why not?
5. What function can be used to add matrices element-wise?
6. How do you find the shape of a NumPy array?
7. What other arithmetic operations can be performed on NumPy arrays?
Grade / Mark:
Staff Signature
8. Implementing programs using written modules and Python Standard Libraries
[Link].8 E
Using Matplotlib Module
DATE:
Objective:
To create different types of graphs (line graph, bar chart, and pie chart) using the Matplotlib
library in Python.
Pre-requisite Knowledge:
Basics of Python programming
Lists and arrays in Python
Basic understanding of plotting graphs
Problem Statement:
Write a Python program to demonstrate the use of Matplotlib to create:
1. Line graph
2. Bar chart
3. Pie chart
Algorithm :
1. Import [Link] as plt.
2. Define the data for plotting (lists or arrays for x and y).
3. Use appropriate functions:
o [Link]() for line graph
o [Link]() for bar chart
o [Link]() for pie chart
4. Add labels, title, and legend (optional).
5. Use [Link]() to display the graph.
Logic:
Flowchart:
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]
A line graph with points marked, showing values of y versus x.
x = ['A', 'B', 'C', 'D']
y = [10, 15, 7, 12]
A bar chart displaying values for categories A, B, C, D.
sizes = [30, 20, 25, 25]
labels = ['Python', 'Java', 'C++', 'JavaScript']
A pie chart showing the percentage distribution of Python, Java, C++, and JavaScript.
Result:
The Python programs successfully created line graphs, bar charts, and pie charts using the
Matplotlib library. All graphs were displayed correctly with appropriate labels and titles.
Viva Questions:
1. What is Matplotlib in Python?
2. How do you import Matplotlib for plotting?
3. What is the difference between [Link]() and [Link]()?
4. How do you add a title and labels to a graph?
5. What does autopct do in a pie chart?
6. How can you change the color and style of the plots?
7. Can Matplotlib plot multiple graphs on the same figure?
Grade / Mark:
Staff Signature
8. Implementing programs using written modules and Python Standard Libraries
[Link].8D
Using SciPy Module
DATE:
Objective:
To perform scientific and mathematical computations using the SciPy library in Python, such as
integration, differentiation, and linear algebra operations.
Pre-requisite Knowledge:
Basics of Python programming
Knowledge of functions, arrays, and lists
Understanding of calculus (integration, differentiation) and linear algebra
Problem Statement:
Write Python programs to perform the following using SciPy:
1. Compute the definite integral of a function
2. Solve linear algebra problems such as matrix multiplication or finding determinants
Algorithm :
Part A: Integration
1. Import the quad function from [Link].
2. Define the function to integrate using lambda or def.
3. Use quad(function, lower_limit, upper_limit) to calculate the definite integral.
4. Display the result.
Part B: Linear Algebra
1. Import [Link] and numpy.
2. Define matrices using [Link]().
3. Perform operations like determinant using [Link](matrix) or solve linear equations using
[Link]().
4. Display the results.
Logic:
Flowchart:
Sample Input / Output:
Result:
The Python programs using SciPy successfully:
Calculated the definite integral of a function
Computed the determinant of a matrix
SciPy can be extended to solve a variety of scientific, engineering, and mathematical problems
efficiently.
Viva Questions:
1. What is SciPy used for in Python?
2. How is SciPy different from NumPy?
3. What function is used to compute definite integrals in SciPy?
4. How do you calculate the determinant of a matrix using SciPy?
5. Can SciPy solve differential equations?
6. How do you solve a system of linear equations using SciPy?
7. Give some real-world applications of SciPy.
Grade / Mark:
Staff Signature
9. Implementing real-time/technical applications using File handling
[Link].9
A Copy from One File to Another
DATE:
Objective:
To write a Python program to copy the contents of one text file to another text file.
Pre-requisite Knowledge:
Basics of Python programming
File handling (open(), read(), write())
Loops and string operations
Problem Statement:
Write a Python program to read content from a source file and write it into a destination file.
Algorithm :
1. Open the source file in read mode.
2. Read the content of the source file using read() or readlines().
3. Open the destination file in write mode (creates the file if it does not exist).
4. Write the content from the source file into the destination file.
5. Close both files.
6. Display a success message.
Logic:
Flowchart:
Sample Input / Output:
Content copied successfully from [Link] to [Link]
Destination file ([Link]) content after copying:
Hello, this is a sample text.
Result:
The Python program successfully copied the contents of the source file to the destination file.
Viva Questions:
1. How do you open a file in Python?
2. What is the difference between read() and readlines()?
3. What modes are available for opening files in Python?
4. How do you write content into a file?
5. What happens if the destination file does not exist?
6. Why is it important to close files after reading or writing?
7. Can you copy binary files using the same method?
Grade / Mark:
Staff Signature
9. Implementing real-time/technical applications using File handling
[Link].9 B
Count Number of Words in a Given File
DATE:
Objective:
To write a Python program to count the total number of words in a text file.
Pre-requisite Knowledge:
Basics of Python programming
File handling (open(), read())
String manipulation (split())
Problem Statement:
Write a Python program to read a text file and count the number of words it contains.
Algorithm :
1. Open the file in read mode.
2. Read the content of the file using read().
3. Split the content into words using the split() method.
4. Count the total number of words using len().
5. Display the total word count.
Logic:
Flowchart:
Sample Input / Output:
Total number of words in the file: 8
Result:
The Python program successfully counted the number of words in the file.
Viva Questions:
1. How do you open a file in Python?
2. What is the difference between read() and readlines()?
3. How does the split() method work?
4. How can you count words in a file without reading the entire file at once?
5. What precautions should be taken when opening files?
6. Can this program handle punctuation correctly? How?
7. How do you handle large files efficiently in Python
Grade / Mark:
Staff Signature
9. Implementing real-time/technical applications using File handling
[Link].9
C Find the Longest Word in a Given Sentence
DATE:
Objective:
To write a Python program to find the longest word in a sentence provided by the user.
Pre-requisite Knowledge:
Basics of Python programming
String manipulation (split(), len())
Loops and conditional statements
Problem Statement:
Write a Python program to accept a sentence from the user and identify the longest word in it.
Algorithm :
1. Read the sentence from the user using input().
2. Split the sentence into words using the split() method.
3. Initialize a variable longest_word to store the longest word found.
4. Loop through each word and compare its length with longest_word.
5. If a word is longer than the current longest_word, update it.
6. Display the longest word.
Logic:
Flowchart:
Sample Input / Output:
Input:
Enter a sentence: Python programming is very interesting
The longest word is: interesting
Result:
The Python program successfully identified the longest word in the given sentence.
Viva Questions:
1. How do you split a sentence into words in Python?
2. How do you find the length of a word or string?
3. How does the program compare lengths of words?
4. What happens if two words have the same maximum length?
5. How can this program be modified to return all words with the maximum length?
6. Can punctuation affect the result? How can it be handled?
7. What are some other string methods useful in text processing?
Grade / Mark:
Staff Signature
10. Implementing real-time/technical applications using Exception handling
[Link]. 10 A
Handling Divide by Zero Error Using Exception
DATE:
Objective:
To write a Python program to handle division by zero errors using exception handling.
Pre-requisite Knowledge:
Basics of Python programming
Arithmetic operations
Conditional statements (if, else)
try, except blocks
Problem Statement:
Write a Python program to perform division of two numbers and handle the case when the
denominator is zero.
Algorithm :
1. Read numerator and denominator from the user using input().
2. Convert inputs to numbers using int() or float().
3. Use a try block to perform the division.
4. If the denominator is zero, a ZeroDivisionError occurs.
5. Catch the exception using an except block and display an appropriate message.
6. Display the result if division is successful.
Logic:
Flowchart:
Sample Input / Output:
Input:
Enter numerator: 10
Enter denominator: 0
Output:
Error: Cannot divide by zero.
Input (valid division):
Enter numerator: 10
Enter denominator: 2
Output:
Result of division: 5.0
Result:
The Python program successfully handled division by zero and displayed an appropriate error
message without crashing.
Viva Questions:
1. What is an exception in Python?
2. What happens if you divide a number by zero without exception handling?
3. How does the try-except block work?
4. What is ZeroDivisionError?
5. Can multiple exceptions be handled in a single try block?
6. How can you display a custom message when an exception occurs?
7. What is the difference between try-except and if-else for error handling?
Grade / Mark:
Staff Signature
10. Implementing real-time/technical applications using Exception handling
[Link]. 10 B
Voter’s Age Validity Using Exception Handling
DATE:
Objective:
To write a Python program to validate a person’s age for voting eligibility using exception
handling.
Pre-requisite Knowledge:
Basics of Python programming
Conditional statements (if, else)
try, except, raise for exception handling
Problem Statement:
Write a Python program to check whether a person is eligible to vote. If the age is less than 18,
raise an exception and display an appropriate message.
Algorithm :
1. Read the age of the person using input().
2. Convert the input to an integer.
3. Use a try block to check if the age is 18 or above.
4. If the age is less than 18, raise a ValueError.
5. Catch the exception using an except block and display a message indicating ineligibility.
6. If age is valid, display that the person is eligible to vote.
Logic:
Flowchart:
Sample Input / Output:
Input (ineligible):
Enter your age: 15
Output:
Error: Not eligible to vote. Age must be 18 or above.
Input (eligible):
Enter your age: 20
Output:
You are eligible to vote.
Result:
The Python program successfully validated voter eligibility using exception handling and
displayed appropriate messages for valid and invalid ages.
Viva Questions:
1. How do you raise an exception in Python?
2. What is the difference between raise and try-except?
3. Can you handle multiple exceptions in a single program?
4. What type of exception is suitable for invalid voter age?
5. Why is exception handling preferred over just using if-else?
6. What will happen if you enter a non-numeric age?
7. How can you modify the program to handle non-numeric inputs safely?
Grade / Mark:
Staff Signature
10. Implementing real-time/technical applications using Exception handling
[Link]. 10 C
Student Mark Range Validation Using Exception Handling
DATE:
Objective:
To write a Python program to validate student marks using exception handling, ensuring marks
are between 0 and 100.
Pre-requisite Knowledge:
Basics of Python programming
Conditional statements (if, else)
try, except, raise for exception handling
Problem Statement:
Write a Python program to check whether the marks entered by a student are valid.
Marks must be between 0 and 100.
If the marks are outside this range, raise an exception.
Algorithm :
1. Read marks from the user using input().
2. Convert the input to a number using int() or float().
3. Use a try block to check if the marks are within the range 0–100.
4. If marks are invalid, raise a ValueError.
5. Catch the exception using an except block and display an appropriate message.
6. If marks are valid, display a message confirming validity.
Logic:
Flowchart:
Sample Input / Output:
Input (invalid marks):
Enter student marks: 120
Output:
Error: Invalid marks! Marks should be between 0 and 100.
Input (valid marks):
Enter student marks: 85
Output:
Marks are valid.
Result:
The Python program successfully validated the student’s marks using exception handling and
displayed appropriate messages for valid and invalid inputs.
Viva Questions:
1. How do you raise a custom exception in Python?
2. What type of exception is suitable for invalid marks?
3. How does the try-except block work?
4. What happens if the input is a non-numeric value?
5. Can multiple exceptions be handled in a single program? How?
6. Why is exception handling preferred over using only if-else?
7. How can this program be modified to keep prompting the user until valid marks are entered?
Grade / Mark:
Staff Signature
11. Exploring Pygame tool
[Link]. 11 A
Simulation of Elliptical Orbit
DATE:
Ex. 38.
Objective:
To simulate and visualize the elliptical orbit of a planet or object around a central body using
Python and Matplotlib.
Pre-requisite Knowledge:
Basics of Python programming
NumPy arrays and mathematical operations
Polar and Cartesian coordinates
Matplotlib plotting
Problem Statement:
Write a Python program to simulate an elliptical orbit using the parametric equations of an
ellipse:
x=acos(t),y=bsin(t)x = a \cos(t), \quad y = b \sin(t)x=acos(t),y=bsin(t)
Where:
aaa = semi-major axis
bbb = semi-minor axis
ttt = parameter varying from 0 to 2π2\pi2π
Algorithm :
1. Import required libraries: numpy and [Link].
2. Define the semi-major axis a and semi-minor axis b.
3. Generate values of t from 0 to 2π2\pi2π using [Link]().
4. Calculate x and y coordinates using the parametric equations of an ellipse.
5. Plot the orbit using [Link](x, y).
6. Add title, labels, grid, and optionally, a marker for the central body.
7. Display the plot using [Link]().
Logic:
Flowchart:
Sample Input / Output:
Output:
A smooth elliptical orbit displayed on the plot.
The central body marked at the origin.
Result:
The Python program successfully simulated an elliptical orbit and visualized it using Matplotlib.
The orbit can be modified by changing the semi-major and semi-minor axes.
Viva Questions:
1. What are the semi-major and semi-minor axes of an ellipse?
2. How do you represent an ellipse using parametric equations?
3. Why do we use [Link]() for simulation?
4. How can the orbit be made more accurate or smooth?
5. How is the central body represented in the plot?
6. What does [Link]('equal') do?
7. How can this simulation be extended to simulate multiple orbits?
Grade / Mark:
Staff Signature
12. Developing a game activity using Pygame
[Link]. 12 A
Simulation of Bouncing Ball
DATE:
Objective:
To simulate and visualize the motion of a bouncing ball under gravity using Python and
Matplotlib.
Pre-requisite Knowledge:
Basics of Python programming
Loops and conditional statements
NumPy arrays and mathematical operations
Matplotlib plotting and animation
Problem Statement:
Write a Python program to simulate a ball dropping from a height and bouncing with a
coefficient of restitution until it comes to rest.
Algorithm :
1. Import required libraries: numpy and [Link] with FuncAnimation.
2. Define initial parameters:
o Initial height h
o Gravity g
o Coefficient of restitution e
o Time step dt
3. Initialize ball position and velocity.
4. Use a loop to update the position and velocity at each time step using physics equations:
o v = v + g*dt
o y = y - v*dt
5. When the ball hits the ground (y <= 0), reverse velocity and multiply by restitution coefficient v
= -v*e.
6. Store positions for plotting.
7. Use Matplotlib to animate the bouncing ball.
Logic:
Flowchart:
Sample Input / Output:
Output:
A red ball repeatedly bounces up and down, gradually losing height due to the coefficient of
restitution.
Result:
The Python program successfully simulated the motion of a bouncing ball under gravity with
diminishing height and displayed it as an animation.
Viva Questions:
1. What is the coefficient of restitution?
2. How does gravity affect the motion of the ball?
3. Why does the ball lose height after each bounce?
4. What is the role of the dt (time step) in simulation?
5. How is the bounce condition implemented in the code?
6. How can you make the simulation more realistic?
7. How can the program be modified to simulate multiple balls?
Grade / Mark:
Staff Signature
12. Developing a game activity using Pygame
[Link]. 12 B
Simulation of Car Racing Game
DATE:
Objective:
To simulate a basic car racing game using Python, allowing a car to move along a track with
simple controls.
Pre-requisite Knowledge:
Basics of Python programming
Loops and conditional statements
Functions and event handling
Pygame library for game development
Problem Statement:
Write a Python program to simulate a car moving on a track. The car can be controlled using the
keyboard (e.g., arrow keys) to move left or right and avoid obstacles.
Algorithm :
1. Import the pygame library and initialize it.
2. Set up the display window for the game.
3. Load or draw the car and track.
4. Define variables for car position and speed.
5. Use a game loop to:
o Detect keyboard input for car movement (left/right).
o Update the car’s position.
o Draw the car and track on the screen.
o Check for collisions (if any obstacles are present).
o Refresh the display using [Link]().
6. End the game when the user closes the window or collides with obstacles.
Logic:
Flowchart:
Sample Input / Output:
Output:
A window opens showing a gray track with a red car.
The car can be moved left or right using the arrow keys.
Result:
The Python program successfully simulated a simple car racing game where the car moves left
and right along a track. The game can be further enhanced with obstacles, score tracking, and
multiple levels.
Viva Questions:
1. What is Pygame and why is it used?
2. How do you create a game window in Pygame?
3. How are keyboard inputs handled in Pygame?
4. How can you add obstacles in the game?
5. What is the purpose of the game loop?
6. How can the car’s speed be adjusted?
7. How would you implement collision detection in this game?
Grade / Mark:
Staff Signature
[Link] BEYOND SYLLBUS OOPS
[Link]. 13 A
Student Result Management System Using Class and Object
DATE:
Objective:
To create a student result management system in Python using class and object-oriented
programming to store and display student marks, calculate total and percentage.
Pre-requisite Knowledge:
Basics of Python programming
Understanding of classes and objects
Functions and methods
Input/output operations
Problem Statement:
Write a Python program using classes and objects to manage student results:
1. Accept student name, roll number, and marks in subjects.
2. Calculate total marks and percentage.
3. Display student details along with total and percentage.
Algorithm :
1. Define a class Student.
2. Use __init__() method to initialize student details (name, roll number, marks).
3. Define a method calculate_total() to calculate total marks.
4. Define a method calculate_percentage() to calculate percentage.
5. Define a method display() to display student information, total, and percentage.
6. Create objects of the class for each student and call the methods.
Logic:
Flowchart:
Sample Input / Output:
Output:
Student Name: Alice
Roll Number: 101
Marks: [85, 90, 78]
Total Marks: 253
Percentage: 84.33%
Result:
The Python program successfully stored student details, calculated total marks and percentage,
and displayed the student result using class and object-oriented programming.
Viva Questions:
1. What is a class and what is an object in Python?
2. What is the purpose of the __init__() method?
3. How do you calculate total and percentage using methods?
4. Can you create multiple objects for different students?
5. How can you extend this program to store results for multiple subjects dynamically?
6. How would you implement grade calculation based on percentage?
7. What are the advantages of using classes and objects in result management?
Grade / Mark:
Staff Signature
[Link] BEYOND SYLLBUS OOPS
[Link]. 13 B
Library Management System Using OOPS
DATE:
Objective:
To design a Library Management System in Python using object-oriented programming
(OOPS) to manage books, issue and return operations.
Pre-requisite Knowledge:
Basics of Python programming
Classes, objects, methods, and attributes
Lists and dictionaries for data storage
Input/output operations
Problem Statement:
Write a Python program using classes and objects to manage a library system that can:
1. Add new books to the library.
2. Display available books.
3. Issue a book to a user.
4. Return a book.
Algorithm :
1. Define a class Library.
2. Use __init__() to initialize the library with a list of books.
3. Define methods:
o display_books() – to show all available books.
o issue_book(book_name) – to issue a book and remove it from available books.
o return_book(book_name) – to return a book and add it to available books.
4. Create an object of the Library class.
5. Use a menu-driven loop to perform operations: display, issue, or return books.
Logic:
Flowchart:
Result:
The Python program successfully implemented a Library Management System using classes
and objects. It can add, issue, return, and display books effectively.
Viva Questions:
1. What is the role of a class and object in this program?
2. How does the __init__() method work?
3. How are books stored in the program?
4. How does the issue_book() method work?
5. What happens if a book to be issued is not available?
6. How can this program be extended to store user details?
7. How can data persistence be achieved in this system?
Grade / Mark:
Staff Signature
[Link] BEYOND SYLLBUS OOPS
[Link]. 13 C
Online Shopping Cart Using OOPS
DATE:
Objective:
To design a shopping cart system in Python using object-oriented programming (OOPS) to
add, remove, and display products along with total cost calculation.
Pre-requisite Knowledge:
Basics of Python programming
Classes, objects, methods, and attributes
Lists and dictionaries
Input/output operations
Problem Statement:
Write a Python program using classes and objects to manage an online shopping cart that can:
1. Add products with price to the cart.
2. Remove products from the cart.
3. Display products in the cart.
4. Calculate total price of products in the cart.
Algorithm :
1. Define a class ShoppingCart.
2. Initialize the cart as an empty dictionary or list in __init__().
3. Define methods:
o add_product(product_name, price) – adds a product and its price to the cart.
o remove_product(product_name) – removes a product from the cart.
o display_cart() – displays products and prices.
o total_price() – calculates and displays total price.
4. Create an object of ShoppingCart.
5. Use a menu-driven loop to perform cart operations.
Logic:
Flowchart:
Sample Input / Output:
Output:
'Laptop' added to cart with price 50000
'Headphones' added to cart with price 1500
Products in Cart:
Laptop : 50000
Headphones : 1500
Total Price: 51500
'Laptop' removed from cart
Products in Cart:
Headphones : 1500
Total Price: 1500
Result:
The Python program successfully implemented an Online Shopping Cart using OOPS. It
allows adding, removing, displaying products, and calculating the total price.
Viva Questions:
1. What is a class and object in Python?
2. How are products stored in the shopping cart?
3. How does the add_product() method work?
4. How is total price calculated?
5. How can this program handle multiple quantities of the same product?
6. How can the program be extended to apply discounts?
7. How can the cart data be saved for persistence?
Grade / Mark:
Staff Signature
[Link] BEYOND SYLLBUS OOPS
[Link]. 13 D
ATM Transaction System Using OOPS
DATE:
Objective:
To design an ATM Transaction System in Python using object-oriented programming
(OOPS) to perform basic banking operations like deposit, withdrawal, and balance inquiry.
Pre-requisite Knowledge:
Basics of Python programming
Classes, objects, methods, and attributes
Conditional statements and loops
Input/output operations
Problem Statement:
Write a Python program using classes and objects to simulate an ATM system that can:
1. Check account balance.
2. Deposit money.
3. Withdraw money with balance validation.
4. Display transaction details.
Algorithm :
1. Define a class ATM.
2. Initialize the account with a balance using __init__().
3. Define methods:
o check_balance() – displays the current balance.
o deposit(amount) – adds amount to balance.
o withdraw(amount) – deducts amount from balance if sufficient funds exist.
4. Create an object of ATM.
5. Use a menu-driven loop to perform operations until the user exits.
Logic:
Flowchart:
Sample Input / Output:
Output:
Current Balance: 5000
Deposited: 2000
Current Balance: 7000
Withdrawn: 1000
Current Balance: 6000
Insufficient balance
Result:
The Python program successfully simulated an ATM Transaction System using OOPS. It can
check balance, deposit, withdraw, and handle insufficient funds properly.
Viva Questions:
1. What is the role of a class and object in this program?
2. How is the account balance stored and updated?
3. What checks are performed before withdrawal?
4. How can you extend the program to handle multiple accounts?
5. How can PIN verification be added?
6. How can transactions be logged for record-keeping?
7. What are the advantages of using OOPS in ATM simulation?
Grade / Mark:
Staff Signature