0% found this document useful (0 votes)
6 views55 pages

r21 - PP Lab Manual

The document outlines the Python Programming Lab curriculum for II B. Tech – I Semester students at Visvodaya Institute of Technology and Science. It includes a list of laboratory experiments designed to teach various Python programming concepts and skills, such as mathematical computations, file handling, and object-oriented programming. The document also provides installation instructions for Python and details on the educational objectives of the lab course.

Uploaded by

pv.vec20
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)
6 views55 pages

r21 - PP Lab Manual

The document outlines the Python Programming Lab curriculum for II B. Tech – I Semester students at Visvodaya Institute of Technology and Science. It includes a list of laboratory experiments designed to teach various Python programming concepts and skills, such as mathematical computations, file handling, and object-oriented programming. The document also provides installation instructions for Python and details on the educational objectives of the lab course.

Uploaded by

pv.vec20
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/ 55

Parvatha Reddy Babul Reddy

VISVODAYA INSTITUTE OF TECHNOLOGY AND SCIENCE


(AUTONOMOUS)
KAVALI, SPSR NELLORE (DT.) – 524201
(Approved by AICTE, New Delhi & Affiliated to JNTUA, Anantapur)
(Accredited by NAAC)
Website: www.visvodayata.ac.in Tel.: 08626-243930

PYTHON PROGRAMMING LAB


II B. Tech – I Semester
Our Vision Our Mission
To produce technically competent  To impart quality technical education in the field of Electronics and
and research-oriented Electronics Communication Engineering through state-of-the art facilities and effective
and Communication Engineers to teaching learning process.
meet the Industrial and Social
 To enrich the faculty and students with research and consultancy skills
requirements. through Industry-Interaction and Training in Emerging areas of Electronics
and Communication Engineering.

 To develop lifelong learning, leadership qualities and ethical values in


learners to meet the societal and industrial needs.

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
[Type text]
II B. TECH - I SEM (R-21) ECE: PP LAB

PBR VISVODAYA INSTITUTE OF TECHNOLOGY &


SCIENCE, KAVALI.
[AUTONOMOUS]
SPSR NELLORE (DT.) – 524201
(Approved by AICTE, New Delhi & Affiliated to JNTUA, Anantapur),
(Accredited by NAAC)
Website: www.visvodayata.ac.in Tel.: 08626-243930

DEPARTMENT OF E.C.E.

PYTHON PROGRAMMING LABORATORY

NAME

ROLL NO.

CLASS II B.TECH. I-SEM


BRANCH ECE
REGULATION R-21

LAB NAME PYTHON PROGRAMMING LAB (21A050701)

ACD.YEAR 2022-23

Name of the staff : 1. ____________________________

2. ____________________________

ECE DEPARTMENT, PBRVITS, KAVALI. i


II B. TECH - I SEM (R-21) ECE: PP LAB

PBR VISVODAYA INSTITUTE OF TECHNOLOGY & SCIENCE, KAVALI [AUTONOMOUS]


B. Tech – II-I Sem LTPC
1 0 2 2
(21A050701) PYTHON PROGRAMMING LAB
LIST OF LABORATORY EXPERIMENTS:
1. Install Python Interpreter and use it to perform different Mathematical Computations.
2. Write a Python Program to find sum of given n numbers.
3. Write a Python Program to generate Fibonacci Numbers up to a given number.
4. Write a Python Program to display multiplication Table of a given Number.
5. Write a Python Program to read a list of names from keyboard, sort them and write them
into a File.
6. Write a Python Program to concatenate two files content and write the result into a new
File.
7. Write a Python Program to perform the addition of two matrices.
8. Write a Python Program to search a given word in the given text file and display the number
of occurrences of the string.
9. Write the step-by-step Solution procedure to find the LCM and GCD (HCF) of 2 given
numbers.
10. Find mean, median, mode for the given set of numbers in a list.
11. Python Code to create module called “mathematics” having functions add (), subtract(),
div(), mul() and access them by another Program.
12. Develop Python program for illustrating the object-oriented features supported by Python.
13. Write a function that draws a Pyramid with #symbols

14. Consider turtle object. Write functions to draw triangle, rectangle, polygon, circle and
sphere. Use object-oriented approach.
15. Using turtles concept draw Olympic Symbol.
16. The time module provides a function, also named time that returns the current Greenwich
Mean Time in “the epoch”, which is an arbitrary time used as a reference point
a. >>> import time
b. >>>time.time () 14377460 94.5735958
Write a script that reads the current time and converts it to a time of day in hours,
minutes, and seconds, plus the number of days since the epoch.
17. Given a text of characters, write a program which counts number of vowels, consonants and
special characters.
18. Write program which performs the following operations on list’s. Don’t use built-in
functions a) Updating elements of a list b) Concatenation of list’s c) Check for member in
the list d) Insert into the list e) Sum the elements of the list f) Push and pop element of list
g) Sorting of list h) Finding biggest and smallest elements in the list i) Finding common
elements in the list
19. Design a Python script using the Turtle graphics library to construct a turtle bar chart
representing the grades obtained by N students read from a file categorizing them into
distinction, first class, second class, third class and failed.
20. Develop Python Program to create Login Screen and evaluate user Input?
CO PYTHON PROGRAMMING LABORATORY
Student should be able to understand the basic concepts of Python Programming
CO1
language such as conditional processing, Loops, and other data structures.
CO2 Ability to explore python especially the built-in objects of Python.
Ability to create practical and contemporary applications such as Machine Learning
CO3
algorithms.

ECE DEPARTMENT, PBRVITS, KAVALI. ii


II B. TECH - I SEM (R-21) ECE: PP LAB

INDEX
Name of the student: Roll No:

Class & Branch: Lab:

LIST OF LABORATORY EXPERIMENTS


Faculty
Exp. No Date Name of the Experiment Page No.
Sign
Install and configure Python IDLE
1
Perform different mathematical computations
2 Sum of given ‘N’ numbers
Generation of fibonacci numbers up to a given
3
number
4 Multiplication table of a given number
5 Reading and writing lists to a file in python
Concatenate two files content and write the result
6
into a new file
7 Addition of two matrices
8 Count occurrences of a word in text file
9 Lcm and gcd (hcf) of two given numbers
Mean, median & mode for the given set of
10
numbers in a list
11 Create own python modules
12 Object-oriented features using python
13 Pyramid with hashes (#) symbols
14 Turtle programming in python
15 Olympic symbol in python using turtle
16 Python time functions – time module
17 Count vowels, consonant and special characters
18 Operations on python list
19 Create login form using python tkinter
20 Calculate grade of student in python
ADDITIONAL EXPERIMENTS
1 Inverted pyramid with hashe (#) symbols
2 Membership operators
3 Display 100 years old person details
4 Reverse a number in python

Signature of the Staff member

ECE DEPARTMENT, PBRVITS, KAVALI. iii


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 1(a)


Dt.
INSTALL AND CONFIGURE PYTHON IDLE

In this, we will learn to install and run Python on your computer. Once we do that, we will
also write our first Python program.
Python is a cross-platform programming language, which means that it can run on multiple
platforms like Windows, macOS, Linux, and has even been ported to the Java and .NET virtual
machines. It is free and open-source.
Install Python Separately: Here's how we can install and run Python on your computer.
1. Download the latest version of Python (https://www.python.org/downloads/)
The most stable Windows downloads are available from the Python for Windows page.
On Windows, we have a choice between 32-bit (labeled x86) and 64-bit (labeled x86–64)
versions, and several flavors of the installer for each.

2. Run the installer file and follow the steps to install Python
During the install process, check Add Python to environment variables. This will add
Python to environment variables, and you can run Python from any part of the
computer.
Step 1: Select Version of Python to download Full Installer and install
 Download windows x86 – 64 executable file only as installer will automatically
install 32 bit or 64 bit of python according to the system configuration.
Step 2: Download Python Executable Installer and install it
 Double-click the executable file, which is downloaded.
 Click on the Add Path check box, it will set the Python path automatically.

ECE DEPARTMENT, PBRVITS, KAVALI. 1


II B. TECH - I SEM (R-21) ECE: PP LAB

 Select install now — the recommended installation options.

Step 3: Wait for it to complete the installation process

Once you finish the installation process, we can run Python.


Step 4: Verification of installation of python in Windows
Run Python in Immediate mode or Interactive Mode:
In Interactive Mode, we can run your script line by line in a sequence. To enter in an
interactive mode, we will have to open Command Prompt on your windows machine and type
‘python’ and press Enter to get the output.

ECE DEPARTMENT, PBRVITS, KAVALI. 2


II B. TECH - I SEM (R-21) ECE: PP LAB

Try typing in 1 + 1 and press enter. We get 2 as the output. This prompt can be used as a
calculator. To exit this mode, type ^Z (ctrl z) or quit() and press enter. To exit the command line,
type exit() and press enter.
Step 5: Run python
Python has been installed in your system, now go to
 Windows search
 Type IDLE
 Open it.
Run your First Python code
Run Python in the Integrated Development Environment (IDE):
We can use any text editing software to write a Python script file.
We just need to save it with the .py extension. But using an IDE can make our life a lot
easier. IDE is a piece of software that provides useful features like code hinting, syntax highlighting
and checking, file explorers, etc. to the programmer for application development.

By the way, when we install Python, an IDE named IDLE is also installed. We can use it to
run Python on your computer. It's a decent IDE for beginners.
When we open IDLE, an interactive Python Shell is opened. IDLE is Python’s Integrated
Development and Learning Environment.
Now we can create a new file and save it with .py extension. For example, hello.py
Write Python code in the file and save it. To run the file, go to Run > Run Module or simply click
F5.

ECE DEPARTMENT, PBRVITS, KAVALI. 3


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 1(b)


PERFORM DIFFERENT MATHEMATICAL
Dt. COMPUTATIONS

AIM: Write a python program to perform different mathematical computations.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
In this, we will learn all about Python’s math module. Mathematical calculations are an
essential part of most Python development. Whether we are working on a scientific project, a
financial application, or any other type of programming endeavor.
For straightforward mathematical calculations in Python, you can use the built-in
mathematical operators, such as addition (+), subtraction (-), division (/), and multiplication (*).
But more advanced operations, such as exponential, logarithmic, trigonometric, or power functions,
are not built in.
The Python math module is an important feature designed to deal with mathematical
operations. It comes packaged with the standard Python release and has been there from the
beginning.
 math.ceil() will return the smallest integer value that is greater than or equal to the given
number.
 floor() will return the closest integer value that is less than or equal to the given number.
This function behaves opposite to ceil().
 As with ceil(), when the input for floor() is an integer, the result will be the same as the
input number.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 4


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:
>>> import math
>>> math.pi
Output: 3.141592653589793
>>> math.tau
Output: 6.283185307179586
>>> # Euler’s number (e) is a constant that is the base of the natural logarithm
>>> math.e
Output: 2.718281828459045
>>> math.factorial(7)
Output: 5040
>>> math.pow(2, 5)
Output: 32.0
>>> 2**5
Output: 32
>>> math.exp(2)
Output: 7.38905609893065

>>> # log2() is used to calculate the log value to the base 2.


>>> math.log2(math.pi)
Output: 1.6514961294723187
>>> # log10() is used to calculate the log value to the base 10.
>>> math.log10(math.pi)
Output: 0.49714987269413385
>>> math.log(math.pi)
Output: 1.1447298858494002

>>> # A complex number is a combination of a real number and an imaginary number.


>>> c = 2+3j
>>> c
Output: (2+3j)
>>> type(c)
Output: <class 'complex'>
>>> c = complex(2, 3)
>>> c
Output: (2+3j)

ECE DEPARTMENT, PBRVITS, KAVALI. 5


II B. TECH - I SEM (R-21) ECE: PP LAB

>>> math.ceil(6)
Output: 6
>>> math.ceil(6.4)
Output: 7
>>> math.floor(5.532)
Output: 5
>>> import math
>>> math.sin(3.14159)
Output: 2.65358979335273e-06
>>> math.sin(0)
Output: 0.0
>>> math.sin(90)
Output: 0.8939966636005579

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 6


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 2
Dt.
SUM OF GIVEN ‘N’ NUMBERS

AIM: Write a Python Program to find sum of given n numbers.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Here, we can how to find the sum of n numbers using a function in python.
 In this example, I have taken an input. The function is defined as def sum(n).
 The if condition is used if the input is less than 1 it returns n itself, if the number is greater
than one the else condition is executed and then n is added to sum(n-1).
 The print(“The sum is: “, sum(num)) is used to get the output.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 7


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 8


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 3 GENERATION OF FIBONACCI NUMBERS UPTO A


Dt. GIVEN NUMBER

AIM: Write a Python program to generate Fibonacci numbers up to a given number

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 9


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 10


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 4
Dt.
MULTIPLICATION TABLE OF A GIVEN NUMBER

AIM: Write a Python program to display multiplication table of a given number.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY: Method: Using For loop


In the following example, we will print the multiplication table of any number (from 1 to
10) by using the for loop. In the below program, we have taken an input integer number from the
user. Then we have iterated for loop using the range (1, 11) function, which means greater than or
equal to 1 and less than 11. In the first iteration, the loop will iterate and multiply by 1 to the given
number. In the second iteration, 2 is multiplied by the given number, and so on.
In our case, we have printed the table of 10. We can provide the different numbers to test
the program.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 11


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 12


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 5 READING AND WRITING LISTS TO A FILE IN


Dt. PYTHON

AIM: Write a Python program to read a list of names from keyboard, sort them and write them into
a File.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Reading and writing files is an important functionality in every programming language.
Almost every application involves writing and reading operations to and from a file. To enable the
reading and writing of files programming languages provide File I/O libraries with inbuilt methods
that allow the creation, updation as well as reading of data from the files.
The open(filepath, mode) is used to open the required file in the desired mode. The open()
method supports various modes of which three are of main concern:
 r: read (default) Python and w: write
 write(): Inserts the string str1 in a single line in the text file.
 read(): used to read data from the file opened using the open() method.
Read a Text file In Python using read(): The file is opened using the open() method in reading r
mode. The data read from the file is printed to the output screen using read() function. The file
opened is closed using the close() method.
Write in a Text file In Python using write(): The file is opened with the open() method in w+
mode within the with block, the w+ argument will create a new text file in write mode with the help
of write(). The with block ensures that once the entire block is executed the file is closed
automatically.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 13


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 14


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 6 CONCATENATE TWO FILES CONTENT AND


Dt. WRITE THE RESULT INTO A NEW FILE

AIM: Write a Python program to concatenate two files content and write the result into a new File.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Let the given two files be file1.txt and file2.txt. Our Task is to merge both files into third file
say file3.txt. The following are steps to merge.
1. Open file1.txt and file2.txt in read mode.
2. Open file3.txt in write mode.
3. Read the data from file1 and add it in a string.
4. Read the data from file2 and concatenate the data of this file to the previous string.
5. Write the data from string to file3
6. Close all the files

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 15


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT: Input data is

Output data is

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 16


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 7
Dt.
ADDITION OF TWO MATRICES

AIM: Write a Python program to perform the addition of two matrices.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY: To represent a matrix, we are using the concept of nested lists. All the elements of both
the input matrices are represented as nested lists. All the elements of output list are initialized as
zero. We are iterating the matrix and adding the corresponding elements of both the given matrices
and assigning the value in the output matrix.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 17


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 18


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 8
Dt.
COUNT OCCURRENCES OF A WORD IN TEXT FILE

AIM: Write a Python program to search a given word in the given text file and display the number
of occurrences of the string.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY: To count the number of occurrences of a specific word in a text file, read the content of
text file to a string and use String.count() function with the word passed as argument to the count()
function. Following is the syntax of count() function. i.e., n = String.count(word)
Where word is the string, and count() returns the number of occurrences of word in this String.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 19


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 20


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 9
Dt.
LCM AND GCD (HCF) OF TWO GIVEN NUMBERS

AIM: Write a Python program to find the LCM and GCD (HCF) of 2 given numbers.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Greatest common Divisior (GCD): In Mathematics, the Greatest Common Divisor (GCD) of two
or more integers is the largest positive integer that divides given integer values.
For example, the GCD value of integer 8 and 12 is 4 because both 8 and 12 are divisible by 1, 2,
and 4 (the remainder is 0), and the largest positive integer among them is 4.
The Greatest Common Divisor (GCD) is also known as Highest Common Factor (HCF), or
Greatest Common Factor (GCF), or Highest Common Divisor (HCD), or Greatest Common
Measure (GCM).
Least Common Multiple (LCM): In Mathematics, the Least Common Multiple (LCM) of two or
more integers is the smallest positive integer that is totally divisible by the given integer values.
Remainder should be zero after division.
For example, the LCM value of integer 2 and 3 is 12 because 12 is the smallest positive integer that
is divisible by both 2 and 3 (the remainder is 0).
The least common multiple is also known as lowest common multiple, or smallest common
multiple of two integers.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 21


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 22


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 10 MEAN, MEDIAN AND MODE FOR THE GIVEN


Dt. SET OF NUMBERS IN A LIST

AIM: Write a Python program to find mean, median & mode for the given set of numbers in a list.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
We probably start by finding the mean (or average), the median, and the mode of the data.
These are central tendency measures and are often our first look at a dataset. We'll first code a
Python function for each measure followed by using Python's statistics module to accomplish the
same task.
 Mean - The average value
 Median - The mid-point value
 Mode - The most common value
Mean of a Sample: If we have a sample of numeric values, then its mean or the average is the total
sum of the values (or observations) divided by the number of values.
Say we have the sample [4, 8, 6, 5, 3, 2, 8, 9, 2, 5]. We can calculate its mean by performing the
operation: (4 + 8 + 6 + 5 + 3 + 2 + 8 + 9 + 2 + 5) / 10 = 5.2
Median of a Sample: The median of a sample of numeric data is the value that lies in the middle
when we sort the data. The data may be sorted in ascending or descending order, the median
remains the same.
Mode of a Sample: The mode is the most frequent observation (or observations) in a sample. If we
have the sample [4, 1, 2, 2, 3, 5], then its mode is 2 because 2 appears two times in the sample
whereas the other elements only appear once.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 23


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 24


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 11
CREATE OWN PYTHON MODULES
Dt.

AIM: Write the Python program for addition, subtraction, multiplication, and division using
function and access them by another Program.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Create Python modules:
 To create a Python module, open a Python script, write some statements and functions, and
save it with .py extension. Later on, we can call and use these modules anywhere in our
program.
 Let’s create a new module named “MathOperations”. This module contains functions to
perform addition, subtraction, multiplication, and division.
 Now, we can call this (MathOperations) module anywhere using the import command, and
we can use these functions to perform the related tasks. There is no need to write the code
again and again for performing addition, subtraction, multiplication, and division
operations.
Call your module:
 Let’s call this module in our other Python script by using the import command. Check out
this, to learn more about the Python import command.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 25


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 26


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 12
Dt.
OBJECT-ORIENTED FEATURES USING PYTHON

AIM: Write a python program using Class and object.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
In Python, object-oriented Programming (OOPs) is a programming paradigm that uses
objects and classes in programming. It aims to implement real-world entities like inheritance,
polymorphisms, encapsulation, etc. in the programming.
Some points on Python class:
 Classes are created by keyword class.
 Attributes are the variables that belong to a class.
 Attributes are always public and can be accessed using the dot (.) operator. Eg.:
Myclass.Myattribute.
An object consists of:
 State: It is represented by the attributes of an object. It also reflects the properties of an
object.
 Behavior: It is represented by the methods of an object. It also reflects the response of an
object to other objects.
 Identity: It gives a unique name to an object and enables one object to interact with other
objects.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 27


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 28


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 13
Dt.
PYRAMID WITH HASHES (#) SYMBOLS

AIM: Write a function that draws a Pyramid with # symbols

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY: To print pyramid pattern of stars, numbers, or alphabets in python, you have to use two
or more for loops. In most of the program that contains two for loops. The first loop corresponds to
rows, whereas the second loop corresponds to columns.
The range() function returns a sequence of values. By default, the value starts with 0 and
increments by 1. It stops before a number specified as argument of the function.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 29


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 30


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 14
Dt.
TURTLE PROGRAMMING IN PYTHON

AIM: Write a program to draw triangle, rectangle, polygon, circle and sphere using python turtle.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
 Turtle graphics is a popular way for introducing programming to kids.
 Turtle is a Python library which used to create graphics, pictures, and games.
 The Logo programming language was popular among the kids because it enables us to draw
attractive graphs to the screen in the simple way. It is like a little object on the screen, which
can move according to the desired position. Similarly, turtle library comes with the
interactive feature that gives the flexibility to work with Python.
 Turtle is a pre-installed library in Python that is similar to the virtual canvas that we can
draw pictures and attractive shapes. It provides the onscreen pen that we can use for
drawing.
 The Python turtle library consists of all important methods and functions that we will need
to create our designs and images. Import the turtle library using the following command.
>>> import turtle
forward(distance) or turtle.fd(distance): It moves the turtle in the forward direction by a certain
distance. It takes one parameter distance, which can be an integer or float.
back(distance) or turtle.bk or turtle.backward(distance): This method moves the turtle in the
opposite direction the turtle is headed. It doesn't change the turtle heading.
right(angle) or turtle.rt(angle): This method moves the turtle right by angle units.
left(angle) or turtle.lt(angle): This method turn the turtle left by angle units.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 31


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

ECE DEPARTMENT, PBRVITS, KAVALI. 32


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 33


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 15
Dt.
OLYMPIC SYMBOL IN PYTHON USING TURTLE

AIM: Write a program to draw Olympic Symbol using Python turtles concept.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
The standard library of the Python programming language now contains a Turtle graphics
module. Turtle in Python, like its Logo ancestor, allows programmers to manipulate one or more
turtles in a two-dimensional space.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 34


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 35


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 16
Dt.
PYTHON TIME FUNCTIONS – TIME MODULE

AIM: The time module provides a function, also named time that returns the current Greenwich
Mean Time (GMT) in “the epoch”, which is an arbitrary time used as a reference point
>>> import time
>>>time.time ()
Write a script that reads the current time and converts it to a time of day in hours, minutes, and
seconds, plus the number of days since the epoch.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Every computer system comes with a clock pre-programmed to a specific date, time, and
time zone. Python time module provides the ability to read, represent, and reset the time
information in many ways.
Essential facts about the Time module:
 The time module wraps around the C runtime library to provide functions for time
manipulation. It has a set of functions which you can call to deal with the system time.
 This module follows the EPOCH convention which refers to the point where the time starts.
It supports the dates and times from the epoch to the year 2038.
 The Unix EPOCH is midnight on 12:00 am January 1, 1970. To determine the EPOCH
value on your system, use the following code.
>>> import time
>>> time.gmtime(0)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0,
tm_wday=3, tm_yday=1, tm_isdst=0)
Note: The function time.gmtime() returns a struct_time object.
 The term “Seconds since the Epoch” or the “No. of Ticks since epoch” represents the time
(in seconds) elapsed since the epoch.
Some time functions return time in DST format. DST is the Daylight Saving Time. It is a
mechanism which moves the clocks forward by 1 hour during the summer time, and back again in
the fall.

ECE DEPARTMENT, PBRVITS, KAVALI. 36


II B. TECH - I SEM (R-21) ECE: PP LAB

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 37


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 17 COUNT VOWELS, CONSONANT, DIGITS AND


Dt. SPECIAL CHARACTERS

AIM: Write a python program which counts number of vowels, consonants and special characters
from the given text of characters or string.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
A string is a sequence of characters. Those characters can be vowels, consonants, digits, or
any special characters. Given a string and the task is to count vowels, consonant, digits and special
character in string. Special character also contains the white space.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 38


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 39


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 18
Dt.
OPERATIONS ON PYTHON LIST

AIM: Write a python program which performs the following operations on list’s: (a) Updating
elements of a list, (b) Concatenation of list’s, (c) Check for member in the list, (d) Insert into the
list, (e) Sum the elements of the list, (f) pop element of list, (g) Sorting of list, (h) Finding biggest
and smallest elements in the list, (i) Finding common elements in the list.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
List is a type of data structuring method that allows storing of the integers or the characters
in an order indexed by starting from 0. List operations are the operations that can be performed on
the data in the list data structure.
A few of the basic list operations used in Python programming are extend(), insert(),
append(), remove(), pop(), slice, reverse(), min() & max(), concatenate(), count(), multiply(), sort(),
index(), clear(), etc.

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PROGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 40


II B. TECH - I SEM (R-21) ECE: PP LAB

ECE DEPARTMENT, PBRVITS, KAVALI. 41


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 42


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 19
Dt.
CREATE LOGIN FORM USING PYTHON TKINTER

AIM: write a Python program to create a Login Form in Python GUI application using tkinter.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

THEORY:
Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a powerful object-
oriented interface to the Tk GUI toolkit.
To create a tkinter app:
1. Importing the module tkinter
2. Create the main window (container)
3. Add any number of widgets to the main window
4. Apply the event Trigger on the widgets.
mainloop(): There is a method known by the name mainloop() is used when your application is
ready to run. mainloop() is an infinite loop used to run the application, wait for an event to occur
and process the event as long as the window is not closed.
Button: To add a button in your application, this widget is used.
The general syntax is: W = Button(parent, options) or w = Button(master, option=value)
Entry: The Entry widget is used to provde the single line text-box to the user to accept a value
from the user. We can use the Entry widget to accept the text strings from the user. It can only be
used for one line of text from the user. For multiple lines of text, we must use the text widget.
The syntax to use the Entry widget is given below.
Syntax: w = Entry(parent, options) or w = Entry(master, option=value)

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

ECE DEPARTMENT, PBRVITS, KAVALI. 43


II B. TECH - I SEM (R-21) ECE: PP LAB

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 44


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 20
Dt.
CALCULATE GRADE OF STUDENT IN PYTHON

AIM: Write a program to calculate grade of students in python.

SOFTWARE REQUIRED:
1. PC with Windows 10
2. IDLE Python 3.8.2 or Above Version

PROCEDURE:
1. Double click on Python IDLE shortcut icon on windows desktop or type IDLE in search bar
and press the enter button.
2. Python IDLE opens up in a shell. Here, we can type code in get the result out.
3. To open an editor screen, "File → New File".
4. Type and save ("File → Save As") the program with filename.py extension.
5. Execute the program, Run → Run Module (Press F5).
6. Observe the output values on Python Shell and observe the waveforms on figure window.

PRAGRAM CODE:

ECE DEPARTMENT, PBRVITS, KAVALI. 45


II B. TECH - I SEM (R-21) ECE: PP LAB

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 46


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 21
Dt.
INVERTED PYRAMID WITH HASHE (#) SYMBOLS

AIM: Write a function that draws an inverted Pyramid with # symbols.

PROGRAM CODE:

# Inverted Full Pyramid of Hashes (#)


print("Inverted Full Pyramid of Hashes (#): ")
for i in range(15):
for h in range(i):
print(" ", end="")
for j in range(i, 15):
print("# ", end="")
print()

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 47


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 22
Dt.
MEMBERSHIP OPERATORS

AIM: Write a program to read a list of numbers and write a program to check whether a particular
element is present or not using membership operators.

PROGRAM CODE:
# Membership Operator
# Python program to illustrate
# not 'in' operator

x = 24
y = 20
list = [10, 20, 30, 40, 50]

if (x not in list):
print("x is NOT present in given list")
else:
print("x is present in given list")
if (y in list):
print("y is present in given list")
else:
print("y is NOT present in given list")

OUTPUT:
x is NOT present in given list
y is present in given list

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 48


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 23
Dt.
DISPLAY 100 YEARS OLD PERSON DETAILS

AIM: Write a Python program to display the year in which you will turn 100 years old.

PROGRAM CODE:
# he/she will turn 100 years old.
name = input ("Enter the Name:: ")
age = int (input("Enter the Age::"))
# Let present year is 2022
user_age = (100 - age) + 2022
print ("The user will in year ", user_age ,"he/she will turn 100 years old.")

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 49


II B. TECH - I SEM (R-21) ECE: PP LAB

Exp. No. 24
Dt.
REVERSE A NUMBER IN PYTHON

AIM: Write a Python program to reverse a number.

PROGRAM CODE:

OUTPUT:

RESULT:

ECE DEPARTMENT, PBRVITS, KAVALI. 50


ABOUT PBRVITS:

PBRVITS was pioneered by technocrats with a lot of industrial and educational experience
with a vision to provide the society with a center of learning that motivates, supports and
encourages the youth to evolve into dynamic professionals with a social commitment. 22 years of
excellence in Engineering education PBRVITS offering both U.G & P.G programs.
PBRVITS is offering a curriculum integrated with soft skills and personality training
through which 100% placements are achieved

HIGHLIGHTS :

 Spacious class rooms with LCD Projectors


 Broadband with 30 Mbps speed
 Central Library with more than 40,000 volumes
 MoU’s with leading Companies like GIPFMA, E-clerx, Repro India Limited, PAMAC
Finserve Pvt Ltd, Sensiple, Hidden Brains, Mobius, Tudip Technologies, Alien
group, Code Tantra, Huawei, Blue Prism Pvt Ltd, Talent Sprint (TSCOC) and many
more companies with more than 3 Lakhs package per annum
 Excellent training and placement
 100% placement assistance
 In-house training-soft skills and technical skills
 Customized career guidance cell
 Personality Development Programs
 Major Research projects worth more than 1 crores
 Wi-Fi enabled campus
 Infosys campus connect program
 IBM center of excellence
 Technology forums, department wise student chapter and hobby clubs
 Indoor, outdoor games and sports Only college in the Nellore district
 Hostel for girls and boys students with a capacity of 1600
 Bus facility from Nellore, Kovur, Buchi, Rajupalem, Kodavaluru, Alluru, Bitragunta,
Vinjamur, Kaligiri, Kandukuru, Kavali town

VISION AND MISSION OF THE INSTITUTE

VISION:

To be a premier centre of learning in Engineering and Management education that evolves the youth into
dynamic professionals with a social commitment

MISSION

 To provide quality teaching-learning practices in engineering and management education by imparting core
instruction and state-of-the-art infrastructure.

 To engage the faculty and students in acquiring competency in emerging technologies and research activities
through Industry Institute Interaction.

 To foster social commitment in learners by incorporating leadership skills and ethical values through value-
based education

You might also like