CCE Python Lab Observation
CCE Python Lab Observation
NAME .............................................................................................................
BRANCH .................................................................................................................
SEMESTER ................................................................................................................
PAGE
S. DATE TITLE SIGNATURE
NO NO
PAGE
S. NO DATE TITLE SIGNATURE
NO
9 Program for File using Python
COURSE OBJECTIVES:
● To develop proficiency in the concepts of lists, tuples, sets, and dictionaries to effectively
address real-world challenges.
● To master the concepts such as functions, strings, modules, file handling, and exception
handling.
● To expose the analysis of various datasets Pandas Data frame, utilizing NumPy arrays and
Pandas Data frames, visualizing the data.
● To exhibit the analysis of various datasets using the Matplotlib package.
● To make real time Projects with different Packages.
LIST OF EXPERIMENTS
TOTAL: 30 PERIODS
COURSE OUTCOMES :
CO1 : Address real time applications using the concepts of lists, tuples, sets, and
dictionaries
CO2 : Manage functions, strings, modules, file handling and exception handling.
CO3 : Visualize the data interpretation by utilizing NumPy arrays and Pandas Dataframes.
CO4 : Plot the real time datasets with the use of Matplotlib.
Page 1
COs-POs & PSOs MAPPING
PO PSO
CO
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3
1 3 2 2 2 2 - - - - - - 1 1 2 1
2 3 2 2 2 2 - - - - - - 1 1 2 1
3 3 1 3 3 - - - - 2 3 3 3 2 2 2
4 3 1 3 3 - - - - 2 3 3 3 2 2 2
5 3 2 2 1 1 - - - 3 2 3 1 3 1 3
Avg. 3 1.6 2.4 2.2 1 0 0 0 1.4 1.6 1.8 1.8 1.8 1.8 1.8
Page 2
[Link]: 1(a) Python Programming Basics – Data Types, Conditional Statements,
AIM:
To understand and implement fundamental Python concepts, including:
● Data types, variables, and expressions.
● Conditional statements (if-elif-else).
● Iterations (for, while, break, continue).
● Functions (recursion, return, scope).
● String operations (counting vowels, consonants, spaces).
● Lists (operations, methods, list comprehension).
● Tuples (assignment, returning multiple values).
1.1 Write a Python program to declare variables of different data types and display their types.
PROGRAM:
a=10
b="harish"
c=False
d=12.45
e=[24,52,False]
f=(12,41,"safd")
g={24:"harish"}
h={22}
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)
print(g)
print(h)
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))
print(type(g))
print(type(h))
OUTPUT:
10
harish
False
12.45
[24, 52, Fals]e
(12, 41, 'safd)'
{24: 'harish}'
{22}
<class 'int>'
<class 'str>'
<class 'bool>'
<class 'float>'
<class 'list>'
<class 'tuple>'
<class 'dict>'
<class 'set>'
Page 3
1.2 Write a Python program to demonstrate different types of type conversions (type casting).
PROGRAM:
a=12
C="24"
d="24.87"
print("Interger to float :",float(a))
b=12.7
print("float to integer:",int(b))
print("string to integer:",int(C))
print("integer to string :",str(a))
print("float to string :",str(b))
OUTPUT:
Interger to float : 12.0
float to integer: 12
string to integer: 24
integer to string : 12
float to string : 12.7
1.3 Write a Python program to create a simple calculatoar that performs addition, subtraction, multiplication,
Division, modulus and floor division using user input.
PROGRAM:
5print("simple calculator")
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
menu=int(input("which operation you like to perform \[Link]\[Link]\[Link]\[Link]\n
if menu == 1:
print("Addition of two numbers:",a+b)
elif menu ==2:
i (" b i f b " b)
print("Subtraction of two numbers:",a-b)
elif menu ==3:
print("Multiplication of two numbers:",a*b)
elif menu ==4:
print("Division of two numbers:",a/b)
elif menu ==5:
print("Modulus of two numbers:",a%b)
else:
print("Invalid input")
print("ThankYou")
def add(a,b):
print("Addition of two numbers:",a+b)
OUTPUT:
simple calculator
Enter first number:23
Enter second number:26
which operation you like to perform
[Link]
[Link]
[Link]
[Link]
[Link]
1
Addition of two numbers: 49
ThankYou
Page 4
1.4 Write a Python program to calculate the area and circumference of a circle.
PROGRAM:
PROGRAM:
1.6 Write a Python program to find whether the given number is even or odd using only if statement and if ..
else Statement.
PROGRAM:
1.7 Develop a Python program to check whether the person is in teen age or not, using if...else statement.
PROGRAM:
OUTPUT:
Enter the age of the person14
The person is in teen age
Page 5
1.8 Develop a Python program to check whether the given year is leap year or not, using if...else statement
PROGRAM:
OUTPUT:
Enter the year to check whether year or not2005
The given year is not a leap year
1.9 Write a Python program to check if the number is positive or negative or zero using if….elif …else
statement.
PROGRAM:
1.10 Write a Python program to find the biggest of 3 numbers using nested if...else statement.
PROGRAM:
OUTPUT:
Enter the first number23
Enter the second number42
Enter the third number52
The biggest number is 52
Page 6
1.11 Develop Python program that will accept roll number, name and mark obtained by a student and assign
grades according to the following conditions, and display the roll number, name, mark and grade:
PROGRAM:
name=str(input("Enter the Name"))
roll=int(input("Enter the roll number"))
mark=int(input("Enter the mark obtained"))
print("Name:",name)
print("Roll Number:",roll)
print("Mark Obtained:",mark)
if mark>90:
print("Grade O")
elif mark>80 and mark<90:
print("Grade A")
elif mark>70 and mark<80:
print("Grade B")
elif mark>60 and mark<70:
print("Grade C")
elif mark>50 and mark<60:
print("Grade D")
else:
print("Grade E")
OUTPUT:
Enter the NameHarishkumar
Enter the roll number24
Enter the mark obtained64
Name: Harishkumar
Roll Number: 24
Mark Obtained: 64
Grade C
1.12 Develop a Python program to calculate electricity bill for domestic consumers as follows:
PROGRAM:
unit=float(input("Enter the total unit"))
if unit<100:
price= unit * 3
print("The electricity bill is",price)
elif unit>101 and unit <200:
price=unit*3.25
print("The electricity bill is",price)
elif unit>201 and unit < 500:
price=700+((unit-200)*4.60)
print("The electricity bill is",price)
elif unit>500:
price=2080+((unit-500)*6.60)
print("The electricity bill is",price)
OUTPUT:
Enter the total unit788
The electricity bill is 3980.8
Page 7
1.13 To create a menu-driven Python program that performs arithmetic operations.
PROGRAM:
choice=0
while choice != 8 :
print("Menu based Arithmetic operator")
menu=int(input("which operation you like to perform \[Link]\[Link]\[Link]\[Link]
if menu== 8:
break
OUTPUT:
Menu based Arithmetic operator
which operation you like to perform
[Link]
2. Subtraction
3. Multiplication
[Link]
[Link]
[Link]
7. Floor division
8. Exit
8
1.14 Write a python program to find sum of n numbers using while loop.
PROGRAM:
sum =0
n = int(input("Enter the number:"))
for i in range(1,n):
sum=sum+n
print(sum)
OUTPUT:
Enter the number:25
600
1.15 Write a python program to find factorial of a number using while loop.
PROGRAM:
Page 8
n=int(input("Factorial Number:"))
fact=1
while n!=0:
fact=fact*n
n=n-1
print(fact)
OUTPUT:
Factorial Number:5
120
1.16 Write a python program to find sum of digits of a number using while loop
PROGRAM:
digit = 0
num=int(input("Enter the number"))
n=num
while n>0:
digit = n%10
sum=sum+digit
n=n//10
print(sum)
OUTPUT:
Enter the number23
605
1.17 Write a python Program to Reverse the given number using while loop.
PROGRAM:
print(rev)
OUTPUT:
Enter the number41
14
1.18 Write a python Program to find number is Armstrong number or not using while loop.
PROGRAM:
Page 9
1.19 Write a python Program to check the number is palindrome or not using while loop.
PROGRAM:
if digit == rev:
print("This is palindrome Number")
else:
print("This is not palindrome Number")
OUTPUT:
Enter the number111
This is palindrome Number
1.20 Write a python Program to print nos divisible by 5 not by 10 using for loop
PROGRAM:
1.21 Write a python Program to print fibonacci series using for loop
PROGRAM:
OUTPUT:
1.22 Write a python Program to find factors of a given number using for loop
Page 10
PROGRAM:
1.23 Write a python program to check the given number is perfect number or not using for loop
PROGRAM:
if n==sum:
print("The number is perfect number")
else:
print("The number is not perfect number")
OUTPUT:
Enter the number52
The number is not perfect number
1.24 To create a menu-driven Python program to count the number of vowels, consonants, special character and
spaces in a given string.
PROGRAM:
Page 11
1.25 Write a Python program to simulate an ATM PIN verification system using control flow statements (break,
continue, and pass).
PROGRAM:
print("Welcome to testing ATM PIN Verification test..)"
pin=1234
chance =0
while chance != 5:
print("Enter the PIN")
check=int(input())
if check != pin:
print("Try again")
chance=chance+1
else:
print("Correct PIN")
break
OUTPUT:
Welcome to testing ATM PIN Verification test..
Enter the PIN
1234
Correct PIN
Page 12
[Link]: 1(b) List Operations and Built-in Methods in Python
Date:
AIM:
To write a Python program that demonstrates all the operations on lists, including:
● List creation and initialization
● Basic operations: indexing, slicing, looping
● Adding and removing elements
● Sorting, reversing, copying, searching
● Mathematical operations on lists
● List comprehension
ALGORITHM:
Page 13
Page 14
Page 15
Page 16
Page 17
[Link]: 1(C) Tuple Operations and Built-in Methods in Python
Date:
AIM:
To write a Python program that demonstrates all the operations on tuples, including:
Tuple creation and initialization
● Accessing elements using indexing and slicing
● Tuple immutability demonstration
● Tuple operations (concatenation, repetition, membership tests)
● Tuple assignment and unpacking
● Tuple as function arguments and return values
● Built-in methods available for tuples
ALGORITHM:
PROGRAM:
Page 18
Page 19
Page 20
Page 21
Page 22
[Link] Implementation of Library management using List
Date:
Aim:
This project aims to create a real-time library management system using lists in Python.
The system should allow users to perform various operations such as adding books,
removing books, displaying available books, checking out books, and returning books.
Page 23
Page 24
Page 25
Page 26
[Link] Implementation of construction material management using list
Date:
Aim:
The Python program for construction materials aims to provide a tool for managing
information about various construction materials, including their names, quantities,
and prices. This program enables with their details.
Algorithm:
Page 27
Page 28
Page 29
Page 30
Page 31
[Link] (a) Set Operations and Built-in Methods in Python
Date:
AIM:
To write a Python program that demonstrates all the operations on sets, including:
● Set creation and initialization
● Adding and removing elements
● Mathematical set operations (union, intersection, difference, symmetric difference)
● Set comprehensions
● Set membership testing
● Iterating over a set
● Built-in methods available for sets
ALGORITHM:
Page 32
Page 33
Page 34
Page 35
Page 36
[Link](b) Dictionary Operations and Built-in Methods in Python
Date:
AIM:
To write a Python program that demonstrates all the operations on dictionaries, including:
● Dictionary creation and initialization
● Adding, updating, and removing elements
● Dictionary traversal (iteration)
● Key-value operations
● Built-in dictionary methodsDictionary comprehension
● Nested dictionaries
● Using get(), items(), keys(), values() methods
ALGORITHM:
PROGRAM:
Page 37
Page 38
Page 39
Page 40
Page 41
[Link] Implementing real-time applications using Sets
Date:
Aim:
The aim of the program is to simulate a basic management system for automobiles. It allows
management of a vehicle catalog, inventory, and analysis of customer preferences.
Algorithm:
1. Define a class Automobile with methods to manage the catalog, inventory, and
customer preferences.
2. Implement methods to add and remove models from the catalog, add vehicles to
the inventory, and sell vehicles.
3. Implement methods to record and update customer preferences, as well as find
common preferences among customers.
4. In the main() function:
o Create an instance of Automobile.
o Populate initial data including catalog models, vehicles in inventory,
and customer preferences.
o Present a menu to the user with options to manage the catalog, inventory,
analyze customer preferences, or exit.
o Based on the user's choice, perform the corresponding actions using
methods from the Automobile class.
Page 42
Page 43
Page 44
Page 45
Page 46
6a). Implementing programs using Functions Factorial
Aim:
The aim of this program is to calculate the factorial of a given number using functions in Python.
Factorial of a non-negative integer n, denoted as n!, is the product of all positive integers less than
or equal to n.
Algorithm:
Program:
Page 47
Page 48
Page 49
6 b). Implementing programs using Functions using largest number in a list
Aim:
The aim of the aim of this program is to provide a simple and modular solution for finding the
largest number in a list, with robust error handling for user input.
Algorithm:
Program:
Page 50
Page 51
Page 52
6 c). Implementing programs using Functions using area of shape
Aim
The aim of the provided code is to create a program that allows users to calculate the area of
different geometric shapes (circle, rectangle, or triangle) based on their choices.
Algorithm:
Program:
Page 53
Page 54
Page 55
Page 56
7. STRING FUNCTIONS USING PYTHON
Aim:
Implement programs using strings to perform various operations such as reversing a string,
checking if a string is a palindrome, counting characters in a string, and replacing characters in a
string.
Algorithm:
1. Implement functions for each operation: reverse a string, check for palindrome, count
characters, and replace characters.
2. For reversing a string, use slicing or iteration.
3. For checking palindrome, compare the string with its reverse.
4. For counting characters, iterate through the string and maintain a count for each character.
5. For replacing characters, iterate through the string and replace the desired characters.
6. Display appropriate outputs for each operation.
Program:
Page 57
Page 58
Page 59
8. Implementing Programs Using Written Modules in Python
AIM:
ALGORITHM:
Page 60
Step 2: Creating a User-Defined Module
Page 61
Step 3: Importing and Using the User-Defined
Page 62
OUTPUT:
Directly
RESULT:
Page 63
9. Program for File using Python
Aim:
Implement a real-time/technical application using file handling to perform operations such as
copying content from one file to another, counting the number of words in a file, and finding the
longest word in a file.
Algorithm:
1. Define functions for each operation: copy content from one file to another, count words,
and find the longest word.
2. For copying content, open the source file in read mode and the destination file in write
mode, then read content from the source file and write it to the destination file.
3. For counting words, read the content from the file and split it into words using
whitespace as a delimiter. Count the number of words obtained.
4. For finding the longest word, split the content into words and iterate through them,
keeping track of the longest word encountered.
5. Display appropriate outputs for each operation.
Program:
Page 64
Page 65
Page 66
Page 67
10. Program for Exception Handling
Aim:
Implement real-time/technical applications using exception handling to handle divide by zero errors,
validate voter's age, and validate student mark ranges.
Algorithm:
1. Define functions for each operation: division with error handling, voter's age validation, and
student mark range validation.
2. Use try-except blocks to catch specific exceptions raised during the execution of operations.
3. Implement logic to check if the input satisfies the conditions (e.g., age >= 18 for voting,
marks within a valid range).
4. Raise custom exceptions with meaningful error messages when input does not meet the criteria.
5. Display appropriate outputs or error messages based on the result of exception handling.
Program:
Page 68
Page 69
Page 70
Page 71
11. Program for Exploratory Data Analysis
Aim:
Perform exploratory data analysis (EDA) on an email dataset. Export all emails as a dataset,
import them into a pandas DataFrame, visualize them, and extract insights from the data.
Algorithm:
Program:
Page 72
Page 73
Page 74
Page 75
12a). Working with NumPy Arrays and Pandas DataFrames
AIM:
To understand and implement various operations on:
● NumPy Arrays – Creation, indexing, slicing, reshaping, mathematical operations,
aggregation, broadcasting, and advanced operations.
● Pandas DataFrames – Creation, data selection, filtering, modifying, handling missing
values, and statistical analysis.
ALGORITHM:
A. NumPy Arrays:
1. Import NumPy and create arrays using array(), zeros(), ones(), arange(), linspace(), and
random.
2. Perform Array Operations – Indexing, slicing, reshaping, concatenation, and
mathematical operations.
3. Aggregation & Broadcasting – Use functions like sum(), mean(), max(), and min().
B. Pandas DataFrames:
1. Import Pandas and create DataFrames using dictionaries, lists, and CSV/Excel files.
2. Perform Data Operations – Selecting columns, filtering rows, modifying values, and
handling missing data.
3. Analyze Data – Use statistical functions like describe(), groupby(), and visualization
methods.
Page 76
Page 77
Step 2: Pandas DataFrame Operations
Page 78
12b). Program for Numpy Array
Aim:
To Perform various operations with NumPy arrays including appending values to the end of an array,
extracting real and imaginary parts of an array of complex numbers, listing the second column
elements from a shape of (3,3) array, and finding the maximum and minimum values from the shape
of a (3,3) array.
Algorithm:
Program:
Page 79
Page 80
Page 81
12c) Program for Pandans Data Frame
Aim:
To Work with Pandas Data Frame to perform operations such as sorting the DataFrame by multiple
columns, selecting rows based on certain conditions, appending a new row to the DataFrame, and then
deleting that newly appended row to return the original DataFrame.
Algorithm:
Program:
Page 82
Page 83
Page 84
13a). BASIC PLOTS USING MATPLOTLIB (DEMONSTRATE
VARIOUS STYLES OF PLOTTING GRAPH)
Aim
ALGORITHM :
PROGRAM :
Page 85
Page 86
Page 87
13b) Write a Python program to draw a scatter plot comparing two subject marks of
Mathematicsand Science. Use marks of 10 students.
Test Data:
math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90,
100] AIM:
To Write a Python program to draw a scatter plot comparing two subject marks of Mathematics
and Science.
ALGORITHM:
Two random variables are taken with random values. The scatter function plots a scatter plot.
The scatter function takes 2 arguments and a label variable gives the label to the plot.
To name the axes X-axis and Y-axis functions are used and to give the title to the plot the title
function is used.
To show the legend the legend function is used and finally to show the plot the show function.
PROGRAM:
Page 88
Page 89
13 c) Write a Python programming to create a pie chart of gold medal
achievements of five mostsuccessful countries in 2016 Summer Olympics.
Read the data from a csv file.
Sample data:
[Link]
country,gold_
medal United
States,46
Great
Britain,27
China,26
Russia,19
Germany,17
AIM:
To Write a Python programming to create a pie chart of gold medal achievements of five most
successful countries in 2016 Summer Olympics.
ALGORITHM:
Create a CSV file (let’s call it [Link]) with the following
structure: country,gold_medal
United States,46
Great Britain,27
China,26
Russia,19
Germany,17
● The first column represents the country names, and the second column represents the
number of gold medals each country won.
● We use pandas to read the data from the CSV file.
● The [Link]() function creates the pie chart, and we customize it with colors, explode
effect, and other parameters.
● The autopct displays the percentage labels on the chart.
● Finally, we add a title and show the chart.
Page 90
PROGRAM:
Page 91
Page 92
Page 93
14. Frequency Distributions, Averages, and Variability
AIM:
ALGORITHM:
A. Frequency Distribution
PROGRAM:
Page 94
Page 95
Page 96
Page 97
15. Normal Curves, Correlation, and Scatter Plots
AIM:
To understand and implement normal distribution curves, correlation analysis, and scatter
plots using Python’s NumPy, Pandas, Matplotlib, and Seaborn libraries.
ALGORITHM:
B. Correlation Analysis
C. Scatter Plot
PROGRAM: