0% found this document useful (0 votes)
5 views27 pages

Vpython 1-5

The document outlines the Skill-Based Lab curriculum for Python Programming at Shah & Anchor Kutchhi Engineering College for the academic year 2023-2024. It includes laboratory outcomes, a list of experiments, and specific programming tasks aimed at developing proficiency in Python, covering topics such as syntax, file handling, object-oriented programming, GUI applications, and machine learning. The course is designed to equip students with practical skills through hands-on programming exercises and projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views27 pages

Vpython 1-5

The document outlines the Skill-Based Lab curriculum for Python Programming at Shah & Anchor Kutchhi Engineering College for the academic year 2023-2024. It includes laboratory outcomes, a list of experiments, and specific programming tasks aimed at developing proficiency in Python, covering topics such as syntax, file handling, object-oriented programming, GUI applications, and machine learning. The course is designed to equip students with practical skills through hands-on programming exercises and projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Mahavir Education Trust's

SHAH & ANCHOR KUTCHHI ENGINEERING


COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

Lab Code ECL405 Lab Name Skill-Base Lab: Python


Programming

Academic Year 2023-2024 Semester IV

Class, Batch SE Course In charge

Laboratory Outcomes (LO)


LO No. LO Statement (At the end of the course, students will be able to …) BL

1 Describe syntax and semantics in Python 1

2 Illustrate different file handling operations 3

3 Demonstrate object-oriented programming in Python 3

4 Design GUI Applications in Python 4

5 Express proficiency in the handling Python libraries for data science 2

6 Develop machine learning applications using Python. 6

List of Experiments
L PS PI
Sr. No. Title
O O

1 a. Write a Python Program for factorial of a 1 1 1.1.2,


given number 2.1.3
b. Write a Python Program for Sum of
squares of first n natural numbers
c. Write a Python code to find the Maximum of
n numbers given in tuple.

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 1
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

2 a. Write a python code to Count occurrences of an element 1 1,2 1.1.2,


in a list 2.1.3,
b. Write a program to carry out the following operations on 4.1.2
the given set
s = {10, 2, -3, 4, 5, 88}
a) Number of items in sets s
b) Maximum element in sets s
c) Minimum element in sets s
d) Sum of all elements in sets s
e) Obtain a new sorted set from s, set s remaining
unchanged
f) Report whether 100 is an element of sets s
g) Report whether -3 is not an element of sets s.

c. Write a python code to demonstrate student information


Student Name Marks (5 student) using Dictionary.
3 a. Create 3 lists – a list of names, a list of ages and a list of 1 2 4.2.1,
salaries. 5.1.2
b.Generate and print a list of tuples containing name, age
and salary from the 3 lists. From this list generate 3 tuples –
one containing all names, another containing all ages and
third containing all salaries
4 a. Write python program to understand different File 2 1,2 1.1.2,
handling operations 2.1.3,
b. Get number of characters, words, spaces and lines in a 4.2.1,
file 5.1.2
c.Python Program to merge two files into a third file
5 a. Write Python program to implement classes, object, Static 3 1,2 4.3.3,
method and inner class 4.3.4,
5.2.2
b. If any integer is given as in input through the keyboard,
write a program to find whether it is odd or even number.

c. If ages of Ram, Shyam, and Ajay are given as an input


through the keyboard, write a program to determine the

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 2
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

youngest of the three.

d. Write a program that prints square root and cube root of


numbers from 1 to 10, up to 4

6 1. Write Python program to create, append, update, and 4 2 5.2.2,


delete records from database using GUI. 6.1.1,
2. Write Python program to obtain histogram of any image 4.3.1

7 1. Write Python Program to add ,subtract, mask image 4 2 5.2.2,


2. Write Python program for histogram equalization 6.1.1,
3. Write Python Program for edge detection 4.3.1

8 1. Write Python program to implement GUI Canvas a 4 2 5.2.2,


application using Tkinter 6.1.1,
4.3.1

9 Evaluate the dataset containing the GDPs of different 5 1,2 1.1.2,


countries to: 2.1.3,
a) Find and print the name of the country with the highest 5.2.2,
GDP b) Find and print the name of the country with the 6.1.1,
lowest GDP 4.3.1
c) Print text and input values iteratively
d) Print the entire list of the countries with their GDPs
e) Print the highest GDP value, lowest GDP value, mean
GDP value, standardized GDP value, and the sum of all the
GDPs

10 Write python program to use SciPy 5 1,2 1.1.2,


There is a test with 30 questions worth 150 marks. The test 2.1.3,
has two types of questions: 5.2.2,
1. True or false – carries 4 marks each 6.1.1,
2. Multiple-choice – carries 9 marks each. Find the number 4.3.1
of true or false and multiple-choice questions.

11 Write python program to study linear regression 6 1,2 1.1.2,


2.1.3,
5.2.2,

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 3
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

6.1.1,
4.3.1

12 Write python program to study decision tree algorithm 6 2 5.2.2,


6.1.1,
4.3.1

13. Mini project 1,2 1,2, 1.1.2,


,3, 3,4 2.1.3,
4,5 5.2.2,
,6 6.1.1,
4.3.1,
7.1.1,
9.1.1,
9.1.2,
10.1.
2,10.
1.1

COURSE IN CHARGE:
Vidya Gogate
Manisha Mane
Manjusha Kulkarni
Amit Tiwari
Pooja P.
Bhumika Tarate

Name: Signature:
Date:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 4
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Experiment No. 1

Aim: Operators in python

Problem Statement:

a. Write a python code to find the Maximum of two numbers entered by user.

b. Write a python program for factorial of a given number

c. Write a python program for sum of squares of first n natural numbers

Theory: Operator in python


Operators are used to perform operations on values and variables. These are the special
symbols that carry out arithmetic and logical computations. The value the operator operates
on is known as Operand. In Python, bitwise operators are used to perform bitwise
calculations on integers.

Python divides the operators in the following groups:

● Arithmetic operators
● Assignment operators
● Comparison operators
● Logical operators
● Identity operators
● Bitwise operators

Sr.No. Operator & Description

1 **
Exponentiation (raise to the power)

2 ~+-
Complement, unary plus and minus (method names for the last two are +@ and -@)

3 * / % //
Multiply, divide, modulo and floor division

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 5
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

4 +-
Addition and subtraction

5 >> <<
Right and left bitwise shift

6 &
Bitwise 'AND'

7 ^|
Bitwise exclusive `OR' and regular `OR'

8 <= < > >=


Comparison operators

9 <> == !=
Equality operators

10 = %= /= //= -= += *= **=
Assignment operators

11 is is not
Identity operators

12 in not in
Membership operators

13 not or and
Logical operators

Programs:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 6
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Write a python code to find the maximum of two numbers entered by user:

PROGRAM

Output:

Write a python program for factorial of a given number:

PROGRAM

Output:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 7
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

Write a python program for sum of squares of first n natural numbers:

PROGRAM

Output:

Experiment No. 2

Aim: Study of Strings, Lists, Tuples, Dictionaries, Sets, Accessing Elements, Properties,
Operations and methods on these data structures.

Problem Statement:

a. Write a Python code to count occurrences of an element in a list

b. Write a program to carry out the following operations on the given set

s = {10,2,-3,4,5,88}

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 8
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
a) Number of items in set s

b) Maximum element in set s

c) Minimum element in set s

d) Sum of all elements in set s

e) Obtain a new sorted set from s, set remaining unchanged

f) Report whether is 100 an element of set s

g) Report whether -3 is not an element of set s

c) Write a Python code to demonstrate student information

Student Name Marks (5 Students)

Theory:

Q.1 Explain various Data Types in Python.

🡪 Various Data Types in Python are as follows:

String: String is sequence of Unicode characters. We can use single quotes or double
quotes to represent strings. Multi-line strings can be denoted using triple
quotes, ''' or ""“.

s = "This is a string”

Slicing operator [ ] can be used with string. Strings are immutable

List: List is an ordered sequence of items. It is one of the most used data type in
Python and is very flexible. All the items in a list do not need to be of the same type.

Declaring a list is pretty straight forward. Items separated by commas are enclosed
within brackets [ ].

>>> a = [1, 2.2, 'python']

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 9
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
We can use the slicing operator [ ] to extract an item or a range of items from a list.
Index starts form 0 in Python

Lists are mutable, meaning, value of elements of a list can be altered.

Tuple: Tuple is an ordered sequence of items same as list. The only difference is that
tuples are immutable. Tuples once created cannot be modified.

Tuples are used to write-protect data and are usually faster than list as it cannot
change dynamically.

It is defined within parentheses () where items are separated by commas.

>>> t = (5,'program', 1+3j)

We can use the slicing operator [] to extract items but we cannot change its value.

Set: Set is an unordered collection of unique items. Set is defined by values separated
by comma inside braces {}. Items in a set are not ordered.

a = {5,2,3,1,4}

print ("a = ", a)

print(type(a))

We can perform set operations like union, intersection on two sets. Set have unique
values. They eliminate duplicates.

Since, set are unordered collection, indexing has no meaning. Hence the slicing
operator [] does not work.

Dictionary: Dictionary is an unordered collection of key-value pairs.

It is generally used when we have a huge amount of data. Dictionaries are optimized
for retrieving data. We must know the key to retrieve the value.

In Python, dictionaries are defined within braces {} with each item being a pair in the
form key: value.

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 10
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Key and value can be of any type.

d = {1:'value','key':2}

type(d) #<class 'dict'>

print("d[1] = ", d[1])

print("d['key'] = ", d['key'])

We use key to retrieve the respective value. But not the other way around

1. Write a Python code to count occurrences of an element in a list

PROGRAM:

OUTPUT:

2. Write a program to carry out the following operations on the given set

s = {10,2,-3,4,5,88}

a) Number of items in set s

b) Maximum element in set s

c) Minimum element in set s

d) Sum of all elements in set s

e) Obtain a new sorted set from s, set remaining unchanged

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 11
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
f) Report whether is 100 an element of set s

g) Report whether -3 is not an element of set s

c) Write a Python code to demonstrate student information

Student Name Marks (5 Students)

PROGRAM:

OUTPUT:

PROGRAM:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 12
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

OUTPUT:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 13
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

Experiment No: 03

Aim: Study of tuple and dictionaries in python


Problem Statement:

1. Create three lists- lists of names, a list of age, a list of salaries.


2. Generate and print a list of tuples containing name, age and salaries
from 3 lists.
3. From this list generate 3 tuples one contains all age, one contains all
names, one contains all the salaries.

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 14
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Theory:
Tuple is the collection of the object much like the lists. The sequence is s of value stored
in the tuple can be any type, and they are indexed by integers. Value of tuple are syntactically
separated by ‘commas. Although it is not necessary, it is more effective way to define tuple.
Sequence of the parenthesis, This help tuple to understand more easily. It is defined within
parentheses () where items are separated by commas. >>> t = (5,'program', 1+3j) we can use
the slicing operator [] to extract items but we cannot change its Value.
Dictionaries: Dictionaries are used to store data values in key: value pairs. A dictionary is a
collection which is ordered*, changeable and does not allow duplicates.

Example:

thisdict ={

"Food_category": "fruit",

"seasonal": "Mango",

"month": "April"

print(thisdict["Food_category"])

Program:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 15
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

Output:

EXPERIMENT -4

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 16
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Aim: To study file handling operations, merging two files into the third file and to get
numbers, character, spaces and lines.

Problem Statement:

a. Write python program to understand different File handling operations


b. Python program – Get number of characters, words, spaces and lines in a file
c. Python Program to merge two files into a third file
Theory:

● What are the different file handlings functions in python?


Ans: File handling is a mechanism by which we can read data of disk files in python program
or write back data from python program to disk files. There are two types of files in data files
such as Binary file and Text file.

Typically there are four types of operations that can be handled by python on files such as-

● Open
● Read
● Write
● Close
The functions for each type are as follows-

1) Opening File - It can be opened for either read, write and append and it is the built-in
function.
▪ open()
Syntax- file_object=open(filename,mode)

The mode in the open function syntax will tell Python as what operation you want to
do on a file.

⮚ For Text File mode


● ‘r’ – Read Mode: Read mode is used only to read data from the file.
● ‘w’ – Write Mode: This mode is used when you want to write data into the file or
modify it. Remember write mode overwrites the data present in the file.

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 17
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
● ‘a’ – Append Mode: Append mode is used to append data to the file. Remember data
will be appended at the end of the file pointer.
● ‘r+’ – Read or Write Mode: This mode is used when we want to write or read the data
from the same file.
● ‘a+’ – Append or Read Mode: This mode is used when we want to read data from the
file or append the data into the same file.

⮚ For Binary File mode

● wb’ – Open a file for write only mode in the binary format.
● ‘rb’ – Open a file for the read-only mode in the binary format.
● ‘ab’ – Open a file for appending only mode in the binary format.
● ‘rb+’ – Open a file for read and write only mode in the binary format.
● ‘ab+’ – Open a file for appending and read-only mode in the binary format.
2) Reading File – To read from file, python provides many functions like
▪ read([n])
Syntax - Filehandle.read([n]) – It reads and return n bytes if n is not specified
it reads entire file.

▪ readline([n])
Syntax- Filehandle.readline([n]) – It reads a line of input if n is specified
reads at most n bytes.

▪ Readlines()
Syntax- Filehandle.readlines() - It reads all lines and returns them in a list.

3) Writing onto Files – It provides functions as


▪ write()
Syntax – Filehandle.write(str1) : Writes string str1 to file referenced by
filehandle

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 18
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
▪ writelines()
Syntax – Filehandle.writelines(L) : Writes all string value in List L as lines to
file referenced by filehandle.

4) Closing File – This is a built-in function in python to close a file.


▪ close ()
Syntax – myfile.close()

a. Write python program to understand different File handling operations

1) To read data
Program:

Output:

2) To write data

PROGRAM:

OUTPUT:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 19
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

3) To append the data

PROGRAM:

OUTPUT:

4) To read and write the data

PROGRAM:

OUTPUT:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 20
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

5) Get number of characters, words, spaces and lines in a file

PROGRAM:

OUTPUT:

6) Program to merge two files into a third file


PROGRAM:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 21
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

OUTPUT:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 22
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Experiment No: 05

AIM: To implement classes, object static Method and inner class.

PROBLEM STATEMENT:

a) Write a python program to implement classes, object, static method and inner class.

b) If any integer is given as in input through the keyboard, write a program to find whether it
is odd or even number.

c) If ages of Ram, Shyam and Ajay are given as an input through the keyboard, write a
program to determine the youngest of three.

d) Write a program that prints square root and cube root of numbers from 1 to 10, up to 4.

THEORY:

Q1) What is a class?

A class is a code template for creating objects. A class is user defined blueprint or prototype
from objects are created. Classes provide a means of bundling data and functionality together.

A class is defined using the class keyword followed by the class name and : operator after
the class name, which allows you to continue in the next indented line to define class
members.

Example- class Myclass:

x=5

Q2) What is Object?

An object is simply a collection of data (variables) and methods (functions) that act on
those data. An object is an instance of a class.

Example- p1= Myclass()

print(p1.x)

Q3) What is static method?

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 23
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Static methods, much like class methods that are bound to a class rather than its object.
They do not require a class instance creation. So, they are not dependent on the state of the
object.

Syntax :

Class C (object)

staticmethod

def fun (arg1,arg2,…):

Q 4) What is the inner class?

A class defined in another class is known as inner class or nested class. If an object is
created using child class means inner class then the object can also be used by parent class or
root class. A parent class can have one or more inner class.

a) Write Python program to implement classes, object, Static method and inner class

PROGRAM:

output:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 24
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

b) If any integer is given as in input through the keyboard , write a program to find
whether it is even or odd.

Program:

Output:

c) If ages of Ram, Shyam and Ajay are given as an input through the keyboard, write a
program to determine the youngest out of three.

Program:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 25
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science

Output:

d) Write a program that prints square roots and cube roots of numbers from 1 to 10 , up to 4.

PROGRAM:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 26
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING
COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
output:

SAKEC, ECS, SE, SEM-IV, 2023-24 SKILL BASED LAB, PYTHON PROG 27

You might also like