0% found this document useful (0 votes)
22 views15 pages

Prac 1 & 2

The document is a lab manual for the Python Lab course (CSL405) at Mahatma Gandhi Mission's College of Engineering and Technology for the academic year 2024-25. It outlines the course objectives, expected outcomes, software requirements, and a list of experiments designed to teach students various aspects of Python programming, including basics, advanced data types, object-oriented programming, and web development. Each experiment includes aims, objectives, outcomes, source code examples, and expected results.

Uploaded by

shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views15 pages

Prac 1 & 2

The document is a lab manual for the Python Lab course (CSL405) at Mahatma Gandhi Mission's College of Engineering and Technology for the academic year 2024-25. It outlines the course objectives, expected outcomes, software requirements, and a list of experiments designed to teach students various aspects of Python programming, including basics, advanced data types, object-oriented programming, and web development. Each experiment includes aims, objectives, outcomes, source code examples, and expected results.

Uploaded by

shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

LAB MANUAL

Programme (UG/PG): UG

Semester: IV

Course Code: CSL405

Course Title: Python Lab

Prepared By: Prof. Amruta Kothavade

Approved By: ----------------------------

LAB MANUAL [IV --- Python Lab] Page 1


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

Objectives:

The main objective of the course is:

1. Basics of Python programming


2. Decision Making, Data structure and Functions in Python
3. Object Oriented Programming using Python
4. Web framework for developing

Outcomes :

At the end of the course the student should be able to:

1. To understand basic concepts in python.


2. To explore contents of files, directories and text processing with python.
3. To develop a program for data structure using built in functions in python.
4. To explore the django web framework for developing python-based web applications.
4. To understand Multithreading concepts using python.

Software Requirements: Python 3.6 and more, Notepad ++, Sqlite, Ms access, Ms SQL

LAB MANUAL [IV --- Python Lab] Page 2


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

List of Experiments

Exp.
Name of Experiment Mapped CO
No
WAP to understand the basics of Python.
i) WAP to check if a Number is Odd or Even.
ii) WAP to develop a simple calculator.
1 iii) WAP to find a given year is a leap or not. 1
iv) WAP to find the factorial of the given number.
v) WAP to evaluate the Fibonacci series for n terms.
vi) WAP to determine whether a given number is Armstrong or not.
Write python programs to understand Advanced data types &
Functions
i) WAP to find circulating „n‟ values using List.
ii) WAP to Check whether an Item Exists in the Python Tuple or not.
iii) WAP to generate and print a dictionary that contains a number
(between 1 and n) in the form (x, x*x)
2 iv) WAP to perform mathematical set operations like union, 1
intersection, subtraction, and symmetric difference.
v) WAP to find the maximum from a list of numbers.
vi) WAP to Perform basic string operations.
vii) WAP to find Sum of N Numbers by importing array modules.
viii) WAP to multiply two matrices.
ix) WAP to swap Two Numbers using functions.
Write python programs to understand concepts of Object Oriented
Programming.
i) WAP to understand Classes, objects, Static method and inner class.
3 1
ii) WAP to understand Constructors.
iii) WAP to understand Inheritance and Polymorphism with Method
overloading and Method Overriding.
Write python programs to understand the concept of modules,
packages and exception handling.
i) WAP to find the distance between two points by importing a math
module.
4 2
ii) WAP to understand Lambda, map, reduce, filter and range
functions.
iii) WAP to understand different types of Exceptions.
iv) WAP to Create and Access a Python Package
Menu driven program for data structure using built in function for link
5 3
list, stack and queue.

LAB MANUAL [IV --- Python Lab] Page 3


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

Write python programs to understand File handling, GUI & database


programming.
i) WAP to find the most frequent words in a text read from a file.
6 2
ii) WAP to understand different file handling operations with pickle.
iv) WAP to design Graphical user interface (GUI) using built-in tools
in python (Tkinter, PyQt,Kivy etc.).
Program to demonstrate CRUD (create, read, update and delete)
7 4
operations on databases (SQLite/ MySQL) using python.
Creation of simple socket for basic information exchange between
8 4
server and client.
9 Programs on Threading using python. 5
Write python programs to understand Data visualization,analysis
10 i) WAP to implement different types of plots using Numpy and 4
Matplotlob
WAP to implement basic operations using pandas like series, data
11 4
frames, indexing, filtering, combining and merging data frames.
Write python programs to understand web programming using python.
12 4
Program to send email and read content of URL.

LAB MANUAL [IV --- Python Lab] Page 4


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

Experiment No1

Name of Student

Roll No

DOP DOS Marks/Grade Signature

Aim: Write a program to understand the basics of Python.


Objectives:
To study the basics of python programming.
Outcome: Students will be able to implement the basics of pythonprogramming.
i) WAP to check if a Number is Odd or Even.
Source Code:
number = int(input("Enter a number: "))
if number % 2 == 0:
print(f"{number} is Even.")
else:
print(f"{number} is Odd.")

Input and Output:

ii) WAP to develop a simple calculator.


Source Code:
print("Welcome to Simple Calculator")
print("Select operation:")

LAB MANUAL [IV --- Python Lab] Page 5


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = input("Enter choice (1/2/3/4): ")
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print(f"The result is: {num1 + num2}")
elif choice == '2':
print(f"The result is: {num1 - num2}")
elif choice == '3':
print(f"The result is: {num1 * num2}")
elif choice == '4':
if num2 != 0:
print(f"The result is: {num1 / num2}")
else:
print("Error: Division by zero is not allowed.")
else:
print("Invalid Input")

Input and Output:

LAB MANUAL [IV --- Python Lab] Page 6


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

iii) WAP to find a given year is a leap or not.


Source Code:
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
Input and Output:

iv) WAP to find the factorial of the given number.

Source Code:
n=int(input("Enter Number : "))
f=1
for i in range(1, n+1):
f=f*i
print("Factorial of",n,"is",f)
Input and Output:

v) WAP to evaluate the Fibonacci series for n terms.


Source Code:
n=int(input("Enter Limit : "))
LAB MANUAL [IV --- Python Lab] Page 7
Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

print("Fibonacci Series :")


fn = 0
sn = 1
print(fn,end=" ")
print(sn,end=" ")
for i in range(3, n+1):
tn=fn+sn
print(tn,end=" ")
fn=sn
sn=tn
Input and Output:

vi) WAP to determine whether a given number is Armstrong or not.

Source Code:
n=int(input("Enter No. : "))
temp = n
rev=0
while temp!=0:
a=temp%10
rev=rev+ (a*a*a)
temp = int(temp/10)
if(n==rev):
print(n," is an Armstrong Number")
else:
print(n," is not an Armstrong Number")
Input and Output:

LAB MANUAL [IV --- Python Lab] Page 8


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

Conclusion: Thus we implemented the basics of python programming..

LAB MANUAL [IV --- Python Lab] Page 9


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

Experiment No.2

Name of Student

Roll No

DOP DOS Marks/Grade Signature

Aim: Write python programs to understand Advanced data types & Functions
Objectives:
To study the basics of python programming.
Outcome: Students will be able to implement the basics of pythonprogramming.

i) WAP to find circulating „n‟ values using List.


Code:
lst = [int(x) for x in input("Enter numbers separated by space: ").split()]

n = len(lst)

print("Circulating 'n' value:", n)

Output:

ii) WAP to Check whether an Item Exists in the Python Tuple or not.
Code:
my_tuple = (10, 20, 30, 40, 50)

item = int(input("Enter the item to check: "))

if item in my_tuple:
print(f"{item} exists in the tuple.")
else:

LAB MANUAL [IV --- Python Lab] Page 10


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

print(f"{item} does not exist in the tuple.")

Output:

iii) WAP to generate and print a dictionary that contains a number (between 1 and n) in the
form (x, x*x)
Code:
n = int(input("Enter a number n: "))

my_dict = {}

for x in range(1, n+1):


my_dict[x] = x * x

print("Dictionary with numbers and their squares:", my_dict)

Output:

iv) WAP to perform mathematical set operations like union, intersection, subtraction, and
symmetric difference.
Code:

LAB MANUAL [IV --- Python Lab] Page 11


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

set1 = {1, 2, 3, 4, 5}
set2 = {4, 5, 6, 7, 8}

union_result = set1 | set2


intersection_result = set1 & set2
subtraction_result = set1 - set2
symmetric_difference_result = set1 ^ set2

print("Union:", union_result)
print("Intersection:", intersection_result)
print("Subtraction:", subtraction_result)
print("Symmetric Difference:", symmetric_difference_result)

Output:

v) WAP to find the maximum from a list of numbers.


Code:
numbers = [10, 20, 30, 40, 50]
max_num = numbers[0]

for num in numbers:


if num > max_num:
max_num = num

print("Maximum number:", max_num)

Output:

vi) WAP to Perform basic string operations.


Code:

LAB MANUAL [IV --- Python Lab] Page 12


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

str1 = "Hello"
str2 = "World"

concatenation = str1 + " " + str2


repetition = str1 * 3
length_str1 = len(str1)
length_str2 = len(str2)

print("Concatenation:", concatenation)
print("Repetition:", repetition)
print("Length of str1:", length_str1)
print("Length of str2:", length_str2)

Output:

vii) WAP to find Sum of N Numbers by importing array modules.


Code:
import array

n = int(input("Enter number of elements: "))


arr = array.array('i', [])

for i in range(n):
num = int(input(f"Enter element {i+1}: "))
arr.append(num)

sum_of_numbers = sum(arr)
print("Sum of numbers:", sum_of_numbers)

Output:

LAB MANUAL [IV --- Python Lab] Page 13


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

viii) WAP to multiply two matrices.


Code:
# Defining the two matrices
matrix1 = [[1, 2], [3, 4]]
matrix2 = [[5, 6], [7, 8]]

# Resultant matrix initialized to zero


result = [[0, 0], [0, 0]]

# Multiplying the matrices


for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
for k in range(len(matrix2)):
result[i][j] += matrix1[i][k] * matrix2[k][j]

# Printing the result


print("Result of multiplication:")
for row in result:
print(row)

Output:

ix) WAP to swap Two Numbers using functions.


Code:
a=5
b = 10
a, b = b, a

print("After swapping:")
LAB MANUAL [IV --- Python Lab] Page 14
Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

print("a =", a)
print("b =", b)

Output:

Conclusion: Thus we implemented the basics of python programming..

LAB MANUAL [IV --- Python Lab] Page 15

You might also like