Python Programming Lab Manual
Python Programming Lab Manual
PREPARED BY
i
SHADAN COLLEGE OF ENGINEERING & TECHNOLOGY
(UGC AUTONOMOUS INSTITUTION)
(NAAC WITH A+ GRADE, NBA ACCREDITED AND ISO 9001:2015 CERTIFICATE INSTITUTION)
Peerancheru, Hyderabad -500086
1. Students are advised to come to the laboratory at least 5 minutes before (to
the starting time), those who come after 5 minutes will not be allowed into
the lab.
2. Plan your task properly much before to the commencement, come prepared
to the lab with the synopsis / program / experiment details.
3. Student should enter into the laboratory with: a. Laboratory observation
notes with all the details (Problem statement, Aim, Algorithm, Procedure,
Program, Expected Output, etc.,) filled in for the lab session. b. Laboratory
Record updated up to the last session experiments and other utensils (if any)
needed in the lab. c. Proper Dress code and Identity card.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the
computer system allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab
observation notebook, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff,
must maintain the discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded
systems, which should be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF
mode during the lab sessions. Misuse of the equipment, misbehaviors with
the staff and systems etc., will attract severe punishment.
9. Students must take the permission of the faculty in case of any urgency to
go out; if anybody found loitering outside the lab / class without permission
during working hours will be treated seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before
he/she leaves the lab after completing the task (experiment) in all aspects.
He/she must ensure the system / seat is kept properly.
ii
SHADAN COLLEGE OF ENGINEERING & TECHNOLOGY
(UGC AUTONOMOUS INSTITUTION)
(NAAC WITH A+ GRADE, NBA ACCREDITED AND ISO 9001:2015 CERTIFICATE INSTITUTION)
Peerancheru, Hyderabad -500086
Course Outcomes:
After completion of the course, the student should be able to
● Verify programs using modular approach, file I/O, Python standard library
Note: The lab experiments will be like the following experiment examples.
iii
SHADAN COLLEGE OF ENGINEERING & TECHNOLOGY
(UGC AUTONOMOUS INSTITUTION)
(NAAC WITH A+ GRADE, NBA ACCREDITED AND ISO 9001:2015 CERTIFICATE INSTITUTION)
Peerancheru, Hyderabad -500086
COLLEGE MISSION
1. To ensure the availability of faculty with excellent research potential.
iv
SHADAN COLLEGE OF ENGINEERING & TECHNOLOGY
(UGC AUTONOMOUS INSTITUTION)
(NAAC WITH A+ GRADE, NBA ACCREDITED AND ISO 9001:2015 CERTIFICATE INSTITUTION)
Peerancheru, Hyderabad -500086
MISSION (CSE)
1. To foster academic excellence by recruiting and retaining highly qualified faculty
with strong research potential, who are committed to continuous learning,
innovation, and the advancement of knowledge in computer science and engineering.
2. To implement outcome-based education through a student-centric learning model
that equips students with the technical skills, critical thinking abilities, and problem-
solving competencies needed to succeed in a rapidly evolving digital landscape.
3. To ensure access to quality education for students from diverse socio-economic
backgrounds, particularly for under privileged sections, and to foster an inclusive culture that
promotes ethical
v
SHADAN COLLEGE OF ENGINEERING & TECHNOLOGY
(UGC AUTONOMOUS INSTITUTION)
(NAAC WITH A+ GRADE, NBA ACCREDITED AND ISO 9001:2015 CERTIFICATE INSTITUTION)
Peerancheru, Hyderabad -500086
vi
PROGRAM SPECIFIC OUTCOMES (PSOS) - CSE
vii
SHADAN COLLEGE OF ENGINEERING & TECHNOLOGY
(UGC AUTONOMOUS INSTITUTION)
(NAAC WITH A+ GRADE, NBA ACCREDITED AND ISO 9001:2015 CERTIFICATE INSTITUTION)
Peerancheru, Hyderabad -500086
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multi-disciplinary environments.
12. Life- long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
ix
List of Experiments
Task Experiment Name Page
no number
ii) Start the Python interpreter and type help () to start the online help
utility.
1
2.Start a Python interpreter and use it as a Calculator.
1-7
3. i) Write a program to calculate compound interest when principal, rate
and number of periods are given.
ii) Given coordinates (x1, y1), (x2, y2) find the distance between two
points
44
333
2222
2 11111 8-10
ii) Write a program to find common values between two arrays. 11-14
3 2. Write a function called gcd that takes parameters a and b and returns
their greatest common divisor.
x
3. Write a function called palindrome that takes a string argument and
returns True if it is a palindrome and False otherwise. Remember that
you can use the built-in function len to check the length of a string.
i). Write a function called remove_duplicates that takes a list and returns
a new list with only the unique elements from the original. Hint: they
don’t have to be in the same order.
iii). Write a python code to read dictionary values from the user.
Construct a function to invert its content. i.e., keys should be values and
values should be keys.
3.i) Add a comma between the characters. If the given word is 'Apple', it
should become 'A,p,p,l,e' ii) Remove the given word in all the places in a
string?
xi
1. a. Write a function called draw_rectangle that takes a Canvas and a
Rectangle as arguments and draws a representation of the Rectangle on
the Canvas.
6 d. Define a new class called Circle with appropriate attributes and 23-25
instantiate a few Circle objects. Write a function called draw_circle that
draws circles on the canvas.
3. Write a python code to read a phone number and email-id from the
user and validate it for correctness.
1. Write a Python code to merge two given file contents into a third file.
3. Write a Python code to Read text from a text file, find the word with 26-28
7 most number of occurrences
4. Write a function that reads a file file1 and displays the number of
words, number of vowels, blank spaces, lower case letters and uppercase
letters.
xii
R23 B.Tech. CSIT Syllabus
PYTHON PROGRAMMING LABORATORY
B.Tech. I Year II Sem. LTPC0032
Week -1:
1. i) Use a web browser to go to the Python website http://python.org. This page contains
information about Python and links to Python-related pages, and it gives you the ability to
search the Python documentation.
ii) Start the Python interpreter and type help () to start the online help utility.
3. i) Write a program to calculate compound interest when principal, rate and number of
periods are given.
ii) Given coordinates (x1, y1), (x2, y2) find the distance between two points
4. Read name, address, email and phone number of a person through keyboard and
print the details.
Week - 2:
1. Print the below triangle using for loop.
44
333
2222
11111
2. Write a program to check whether the given input is digit or lowercase character or
uppercase character or a special character (use 'if-else-if' ladder)
4. Python program to print all prime numbers in a given interval (use break)
xiii
Week - 3:
1. i) Write a program to convert a list and tuple into arrays.
2. Write a function called gcd that takes parameters a and b and returns their greatest
common divisor.
3. Write a function called palindrome that takes a string argument and returns True if it
is a palindrome and False otherwise. Remember that you can use the built-in function len
to check the length of a string.
Week - 4:
1. Write a function called is_sorted that takes a list as a parameter and returns True if the
list is sorted in ascending order and False otherwise.
2. Write a function called has_duplicates that takes a list and returns True if there is any
element that appears more than once. It should not modify the original list.
i). Write a function called remove_duplicates that takes a list and returns a new list with
only the unique elements from the original. Hint: they don’t have to be in the same
order.
ii). The wordlist I provided, words.txt, doesn’t contain single letter words. So you might
want to add “I”, “a”, and the empty string. iii). Write a python code to read dictionary
values from the user. Construct a function to invert its content. i.e., keys should be
values and values should be keys.
2. i) Add a comma between the characters. If the given word is 'Apple', it should
become 'A,p,p,l,e'
iii) Write a function that takes a sentence as an input parameter and replaces the first
letter of every word with the corresponding upper case letter and the rest of the letters in
the word by corresponding letters in lower case without using a built-in function?
3. Writes a recursive function that generates all binary strings of n-bit length
Week - 5:
1. i) Write a python program that defines a matrix and prints
xiv
2. How do you make a module? Give an example of construction of a module using
different geometrical shapes and operations on them as its functions.
Week-6:
1. a. Write a function called draw_rectangle that takes a Canvas and a Rectangle as
arguments and draws a representation of the Rectangle on the Canvas.
b. Add an attribute named color to your Rectangle objects and modify draw_rectangle
so that it uses the color attribute as the fill color.
c. Write a function called draw_point that takes a Canvas and a Point as arguments and
draws a representation of the Point on the Canvas.
d. Define a new class called Circle with appropriate attributes and instantiate a few
Circle objects. Write a function called draw_circle that draws circles on the canvas.
3. Write a python code to read a phone number and email-id from the user and validate
it for correctness.
Week- 7
1. Write a Python code to merge two given file contents into a third file.
2. Write a Python code to open a given file and construct a function to check for given
words present in it and display on found.
3. Write a Python code to Read text from a text file, find the word with most number of
occurrences
4. Write a function that reads a file file1 and displays the number of words, number of
vowels, blank spaces, lower case letters and uppercase letters.
Week - 8:
1. Import numpy, Plotpy and Scipy and explore their functionalities.
3. Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-OR
4. Write a program to implement Half Adder, Full Adder, and Parallel Adder
5. Write a GUI program to create a window wizard having two text labels, two text fields
and two buttons as Submit and Reset.
xv
TEXT BOOKS:
1. Supercharged Python: Take your code to the next level, Overland
REFERENCE BOOKS:
1. Python for Data Science, Dr. Mohd. Abdul Hameed, Wiley Publications - 1 st Ed.
2021.
xvi
Course Objectives:
To install and run the Python interpreter
Course Outcomes:
After completion of the course, the student should be able to
● Verify programs using modular approach, file I/O, Python standard library
Note: The lab experiments will be like the following experiment examples.
CO-PO mapping:
CO PO PO PO PO PO PO PO PO PO PO PO PO
1 2 3 4 5 6 7 8 9 10 11 12
Python CO1 1 2 1 1 1 2
program
ming CO2 5 2 2 2
Lab
CO3 1 2 2 1 1 2
CO4 2 3 2 4 2
xvii
1
2
3
4
5
6
7
8
9
10
Print (np. intersect 1d (ar1, ar2))
11
enter another number:25
12
13
14
15
16
Result: [‘a’,’p’,’p’,’l’,’e’]
17
18
19
20
21
22
Obj.m()
23
24
25
26
27
28
29
30
31
32
33
34
History of Python
The programming language Python was conceived in the late 1980s,] and its implementation
was started in December 1989 by Guido van Rossum at CWI in the Netherlands as a
successor to ABC capable of exception handling and interfacing with the Amoeba operating
system. Van Rossum is Python's principal author, and his continuing central role in deciding
the direction of Python is reflected in the title given to him by the Python
community, Benevolent Dictator for Life (BDFL). (However, Van Rossum stepped down as
leader on July 12, 2018.). Python was named after the BBC TV show Monty Python's Flying
Circus.
Python 2.0 was released on October 16, 2000, with many major new features, such as list
comprehensions, cycle-detecting garbage collector (in addition to reference counting)
and reference counting, for memory management and support for Unicode, along with a
change to the development process itself, with a shift to a more transparent and community-
backed process.
Python 3.0, a major, backwards-incompatible release, was released on December 3, 2008 after
a long period of testing. Many of its major features have also been backported to the
backwards-compatible, though now-unsupported, Python 2.6 and 2.7. Releases of Python 3
include the 2to3 utility, which automates the translation of Python 2 code to Python 3.
Early history:
In February 1991, Van Rossum published the code (labeled version 0.9.0) to
alt.sources. Already present at this stage in development were classes with inheritance,
exception handling, functions, and the core datatypes of list, dict, str and so on. Also in this
initial release was a module system borrowed from Modula-3; Van Rossum describes the
module as "one of Python's major programming units”. Python’s exception model also
resembles Modula-3's, with the addition of an else clause. In 1994 comp.lang.python, the
primary discussion forum for Python, was formed, marking a milestone in the growth of
Python's user base and popularity.
Table of versions:
35
Version Latest micro Release date End of full End of
version support security fixes
36
3.5 3.5.10 2015-09-13 2017-08-08 2020-09-30
3.6 3.6.15 2016-12-23 2018-12-24 2021-12-23
3.7 3.7.17 2018-06-27 2020-06-27 2023-06-06
3.8 3.8.20 2019-10-14 2021-05-03 2024-10-07
3.9 3.9.21 2020-10-05 2022-05-17 2025-10
3.10 3.10.16 2021-10-04 2023-04-05 2026-10
3.11 3.11.11 2022-10-02 2024-04-02 2027-10
3.12 3.12.9 2023-10-02 2025-05 2028-10
3.13 3.13.2 2024-10-07 2026-05 2029-10
3.14 3.14.0 2025-10-01 2027-05 2030-10
:
Old version, not maintained
Old version, still maintained
Latest version
Latest preview version
Future version
37
Viva Question:
1. What is Python? Why is it called an interpreted language?
6. Explain the difference between a list, tuple, set, and dictionary in Python.
11. What are Python classes and objects? How do you define a class in Python?
14. What is the purpose of try, except, else, and finally blocks?
19. What are Python decorators, and how are they used?
38