22CS206ES : PYTHON PROGRAMMING LABORATORY
[Link] I Year II Sem. L T P C
0 1 2 2
Course Objectives:
To install and run the Python interpreter
To learn control structures.
To Understand Lists, Dictionaries in python
To Handle Strings and Files in Python
Course Outcomes: After completion of the course, the student should be able to
1. Develop the application specific codes using python.
2. Understand Strings, Lists, Tuples and Dictionaries in Python
3. Verify programs using modular approach, file I/O, Python standard library
4. Implement Digital Systems using Python
5. Learn NUmpy, PlotPy, SCIpy packages
Note: The lab experiments will be like the following experiment examples.
PO PO PO PO PO PO PO PO PO PO1 PO PO PSO PSO
1 2 3 4 5 6 7 8 9 0 11 12 1 2
CO1 2 3 2 2 3 2 1
CO2 2 2 2 2 3 2 2
CO3 2 2 2 3 2 3
CO4 2 2 2 2 3 2 2 3
CO5 2 2 2 2 3 2 2 3
Week-1:
1. i)Use a web browser to go to the Python website [Link] 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.
2. Start a Python interpreter and use it as a Calculator.
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
[Link] 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.
5
44
3 33
2 222
1 1111
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)
3. Python Program to Print the Fibonacci sequence using while loop
4. Python program to print all prime numbers in a given interval(use break)
Week-3:
1. i)Write a program to convert a list and tuple into arrays.
ii)Write a program to find common values between two 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, [Link], 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.
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?
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 lowercase with out using a built-in
function?
4. Write 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
ii) Write a python program to perform addition of two square matrices
iii) Write a python program to perform multiplication of two square matrices
2. How do you make a module? Give an example of construction of a module using
different geometrical shapes and operations on the masits functions.
3. Use the structure of exception handling all general-purpose exceptions.
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
rectangles 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 are presentation 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.
2. Write a Python program to demonstrate the usage of Method Resolution
Order(MRO) in multiple levels of Inheritances.
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, lowercase letters and uppercase letters.
Week-8
1. Import numpy, Plotpy and Scipy and explore their functionalities.
2. a) Install NumPy package with pip and explore it.
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.
TEXTBOOKS:
1. Super charged Python: Take your code to the next level, Overland
2. Learning Python, MarkLutz, O'reilly
REFERENCE BOOKS:
1. Python Programming: A Modern Approach, Vamsi Kurama, Pearson
2. Python Programming A Modular Approach with Graphics, Database, Mobile,
and Web Applications, Sheetal Taneja, Naveen Kumar, Pearson
3. Programming with Python, A User’s Book, Michael Dawson, Cengage Learning, India
Edition
4. Think Python, Allen Downey, Green Tea Press
5. Core Python Programming, [Link], Pearson
6. Introduction to Python, Kenneth [Link], Cengage