Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Exp No: 1

Title: Write python program to compute prime factors of an integer

Lab Code :

Output :

SE_ECS_Python Lab(23-24) Roll no: 10395


Post lab :

1. What will be the output of the following code?

Output:-

2. What will be the output of the following code?

SE_ECS_Python Lab(23-24) Roll No: 10395


Output:-

3. What will be the output of the following code?

Output:-

4. What is docstring in Python?


A docstring in Python is a string literal used to document modules, functions, classes,
or methods. It provides information about what the object does, its parameters, return
values, and usage examples. Docstrings improve code readability, aid in
understanding, and serve as a reference for users. They can be accessed using the
`__doc__` attribute of the object.

SE_ECS_Python Lab(23-24) Roll No: 10395


Title: Write a Python Program to print Pascal's Triangle

Lab Code :

Output :

SE_ECS_Python Lab(23-24) Roll No: 10395


Post lab :

1. Write a Python program to accept number from user and calculate the sum of all
number between 1 and given number.

SE_ECS_Python Lab(23-24) Roll No: 10395


Exp No:_2_

Title: Study Strings in Python

Lab Code/Theory :
Problem Definition: Write Python programs

a. To Count the Occurrences of Each Word in a Given String Sentence.

print('//Program To Count the Occurrences of Each Word in a


Given String Sentence.//')
a=str(input('Enter a string:'))
b=str(input('Enter word:'))
count=a.count(b)

print('Occurence of the given word: ',count)

SE_ECS_Python Lab(23-24) Roll No:10395


b. To find duplicate characters in a given string.

print('///To find duplicate characters in a given string. ///')


a=input('Enter a string: ')
l=list(a) l1=[] for i in l:
if i not in l1 and a.count(i)>1:
l1.append(i)
print("".join(l1))

c. To remove punctuations from a string.

print('///To remove punctuations from a string.///')


a=str(input('Enter a string: '))
b='/?.,;:'"+=_-!^\*"
l=list(a)
l1=[]
for i in l:
if i not in b:
l1.append(i)
print("".join(l1))

SE_ECS_Python Lab(23-24) Roll No:10395


d. To Check if a Substring is Present in a Given String

print('//Program to check if substring is present in given


string//') a=str(input('Enter a string: '))
b=str(input('Enter substring to be checked: '))
if (b in a):
print('Substring Present')
else:
print('Substring Is Absent')

Post lab :

1. What will be the output of above Python code?


str1="6/4"

print("str1")

SE_ECS_Python Lab(23-24) Roll No:10395


Exp No: 3

Title: Write Python programs to sort a List of Tuples by the Last Element in Each
Tuple, to remove the Duplicates from a List and to Read a List of Words and Return
the Length of the Longest One.

Lab Code :

1. To sort a list of tuples by the last element in each tuple.

SE_ECS_Python Lab(23-24) Roll No: 10395


2. To remove the Duplicates from a List.

3. To Read a List of Words and Return the Length of the Longest One.

SE_ECS_Python Lab(23-24) Roll No: 10395


Exp No: 4

Title: Write Python scripts using functions.


Lab Code/Theory :
Problem Definition:Write python programs
a. To generate and print a dictionary that contains a number (between 1 and n) in the form
(x,x*x).

b. To merge two dict,

c. To sort a dictionary by key, to remove a key,

SE_ECS_Python Lab(23-24) Roll No:10395


d. To print all unique values in a dictionary.

e. To find the highest 3 values in a dictionary.

f. To Count the Frequency of Words Appearing in a String Using a Dictionary.

SE_ECS_Python Lab(23-24) Roll No:10395


Post lab :
1. Write a program that creates a dictionary of cubes of odd numbers in a range 1 – 10.

2. Write a program that inverts a dictionary. That is, it makes key of one dictionary as a
value of another and vice versa.

3. Write a program that combines the lists to a dictionary.

SE_ECS_Python Lab(23-24) Roll No:10395


SE_ECS_Python Lab(23-24) Roll No:10395
FR. CONCEICAO RODRIGUES COLLEGE OF ENGINEERING
Department of Electronics and Computer Science

Class :S.E. (Semester IV) Subject Name: Python Programming(ECL 404)

Name of Student Harshid Modi

Lab Experiment 5 Roll No. 10395


No.
Date Of Date Of
Performance.: Sub.:
Expt. Title Write Python scripts for demonstrating Object Oriented Programming

CO Mapping ECL404.3

Problem Definition: Write python programs


a. Create a Student class and initialize it with name and roll number. Make methods to :
1. Display - It should display all information of the student.
2. setAge - It should assign age to student
3. setMarks - It should assign marks to the student.

b. Create a Time class and initialize it with hours and minutes.


1. Make a method addTime which should take two time object and add them. E.g.- (2 hour
and 50 min)+(1 hr and 20 min) is (4 hr and 10 min)
2. Make a method displayTime which should print the time.
3. Make a method DisplayMinute which should display the total minutes in the Time. E.g.- (1
hr 2 min) should display 62 minutes

.
Objective of the Experiment: Understanding the concept of Classes and Objects in Python.

Theory:

Python is an object oriented programming language. Unlike procedure oriented


programming, where the main emphasis is on functions, object oriented programming
stresses on objects .An object is simply a collection of data (variables) and methods
(functions) that act on those data. Similarly, a class is a blueprint for that object.
Like function definitions begin with the def keyword in Python, class definitions begin with
a class keyword.The first string inside the class is called docstring and has a brief description
about the class. Here is a simple class definition.
Class MyNewClass:
:”This is a docstring. I have created a new class”
pass

Attach the Source code and output:


Note:-students are expected to paste screenshot of the program with output

The program was tested for different sets of inputs.


Program is working is SATISFACTORY NOT SATISFACTORY ( Tick
appropriate outcome)

Post Lab Questions:

1. Write a Python class which has two methods get_String and print_String. get_String
accept a string from the user and print_String print the string in upper case
FR. CONCEICAO RODRIGUES COLLEGE OF ENGINEERING
Department of Electronics and Computer Science

Class :S.E. (Semester IV) Subject Name: Python Programming(ECL 404)

Name of Student Naimish Purohit

Lab Experiment 6 Roll No. 10395


No.
Date Of Date Of
Performance.: Sub.:
Expt. Title Write Python scripts for demonstrating Inheritance and method overriding in
Object Oriented Programming

CO Mapping ECL404.3

Problem Definition: Write python programs


a. Define a class named Employee. Define two subclasses: Engineer and Manager. Every
class should have a method named PrintDesignation(). This method should print "Engineer"
for Engineer class, "Manager" for Manager class and "Employee" for Employee class

.
Objective of the Experiment: Understanding the concept of Inheritance and method over
riding in Python.

Theory:

It refers to defining a new class with little or no modification to an existing class. The new
class is called derived (or child) class and the one from which it inherits is called the base
(or parent) class.
Python Inheritance Syntax:

class BaseClass:

Body of the base class

class DerivedClass(BaseClass):

Body of DerivedClass

Derived class inherits features from the base class where new features can be added to it. This
results in re-usability of code.

Attach the Source code and output:


Note:-students are expected to paste screenshot of the program with output

The program was tested for different sets of inputs.


Program is working is SATISFACTORY NOT SATISFACTORY ( Tick
appropriate outcome)
Exp No: 7

Title: Write Python scripts for file handling operations

Lab Code:
a. To count number of lines, words and characters in the file

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


b. To read data from a file and calculate the percent count of vowels and consonants.

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


Post lab :
1. Write a python script using os module to change the current working directory

Output:

2. Write a python script using os module to list directories

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


3. Write a python script using os module to delete a directory

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


Exp No: 8
Title: Write Python scripts for NumPy operations

Lab Code :

1. Create a 1D NumPy array from the list

Output:

2. Create a 2D NumPy array from the list

Output:

3. Create 4 x 4 NumPy array from 1 to 16

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


4. Use a tuple [1,2,3,4] to create NumPy array

Output:

5. Get the sum of second and third elements of the above array

Output:

6. Create a 7 by 7 NumPy array from 1 to 49. Extract the middle element

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


7. Create a 4 by 4 NumPy array from 1 to 16 .Extract the last row

Output:

8. Write two 2 D NumPy arrays and perform matrix multiplication

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


9. Convert to the following forms

A.

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


B.

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


C.

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


Post lab :

1. There is an array :[[0,0,0],[1,2,3],[4,5,6]]. Add the elements of the first column by 10, second
column by 20 and third column by 30. Use NumPy broadcasting

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


Exp No: 9

Title: Write Python scripts using Matplotlib and Numpy

Lab Code:

1. Display a simple line plot of angle in radians vs. its sine value in Matplotlib

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


2. Plot Discrete time unit step function with 10 points

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


3. Plot Discrete time ramp function with 10 points

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


4. Plot Discrete time delta function with 10 points

Output:

SE_ECS_Python Lab(23-24) Roll No: 10395


Post lab:

1. Write a python program to plot a circle using Circle() function

SE_ECS_Python Lab(23-24) Roll No: 10395


Exp No: 10

Title: Write Python scripts using OpenCV for Image Processing

Lab Code: Write python programs to demonstrate different image processing

SE_ECS_Python Lab(23-24) Roll No: 10395


SE_ECS_Python Lab(23-24) Roll No: 10395
SE_ECS_Python Lab(23-24) Roll No: 10395
SE_ECS_Python Lab(23-24) Roll No: 10395
SE_ECS_Python Lab(23-24) Roll No: 10396
Threshold value: 127.0

SE_ECS_Python Lab(23-24) Roll No: 10396

You might also like