Python Lab List (Final)
Python Lab List (Final)
LIST OF EXPERIMENTS
LOOPS
1. Write a Python program which accepts a sequence of comma separated 4 digit binary numbers as
its input and print the numbers that are divisible by 5 in a comma separated sequence.
Sample Data : 0100,0011,1010,1001,1100,1001
Expected Output : 1010
2. Write a Python program that accepts a string and calculate the number of digits and letters.
Sample Data : Python 3.2
Expected Output :
Letters 6
Digits 2
FUNCTIONS
3. Write a Python function to calculate the factorial of a number (a non-negative integer). The
function accepts the number as an argument.
5. Write a Python function that accepts a string and calculate the number of upper case letters and
lower case letters.
Sample String : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
6. Write a Python function that takes a list and returns a new list with unique elements of the first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]
STRINGS
2. Write a Python program to count the number of characters (character frequency) in a string.
Sample String : ‘google.com'
Expected Output : {'o': 3, 'g': 2, '.': 1, 'e': 1, 'l': 1, 'm': 1,
'c': 1}
3. Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string.
If the string length is less than 2, return instead of the empty string.
Sample String : 'w3resource'
Expected Result : 'w3ce'
Sample String : 'w3'
Expected Result : 'w3w3'
Sample String : 'w'
Expected Result : Empty String
4. Write a Python program to get a string from a given string where all occurrences of its first char
have been changed to '$', except the first char itself.
Sample String : 'restart'
Expected Result : 'resta$t'
5. Write a Python program to get a single string from two given strings, separated by a space and
swap the first two characters of each string.
Sample String : 'abc', 'xyz'
Expected Result : 'xycabz'
6. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the
given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is
less than 3, leave it unchanged.
Sample String : 'abc'
Expected Result : 'abcing'
Sample String : 'string'
Expected Result : 'stringly'
7. Write a Python program to find the first appearance of the substring 'not' and 'poor' from a given
string, if 'not' follows the 'poor', replace the whole 'not'...'poor' substring with 'good'. Return the
resulting string.
Sample String : 'The lyrics is not that poor!'
'The lyrics is poor!'
Expected Result : 'The lyrics is good!'
'The lyrics is poor!'
8. Write a Python function that takes a list of words and returns the length of the longest one.
DATA STRUCTURES
2. Write a Python program to sort a list of elements using the insertion sort algorithm.
Sample Data: [14,46,43,27,57,41,45,21,70]
Expected Result : [14, 21, 27, 41, 43, 45, 46, 57, 70]
3. Write a Python program to sort a list of elements using the merge sort algorithm.
4. Write a Python program to sort a list of elements using the quick sort algorithm.
5. Write a Python program to create a queue and display all the members and size of the queue.
Expected Output: Members of the queue:
0 1 2 3
Size of the queue:
4
CLASSES
1. Write a Python class to find the three elements that sum to zero from a set of n real numbers.
Sample Input array : [-25, -10, -7, -3, 2, 4, 8, 10]
Expected Output : [[-10, 2, 8], [-7, -3, 10]]
4. Write a Python class which has two methods get_String and print_String. get_String accept a string
from the user and print_String print the string in upper case.
5. Write a Python class named Rectangle constructed by a length and width and a method which will
compute the area of a rectangle.
6. Write a Python class named Circle constructed by a radius and two methods which will compute
the area and the perimeter of a circle.
7. Write a python Program to create a base class Person, which represents any person associated with
a university. Then create a subclass to representstudents and one to represent staff members, and
then a subclass of Staff Member for people who teach courses.
FILES
3. Write a Python program to append text to a file and display the text.
5. Write a Python program to read a file line by line and store it into a list.
6. Write a Python program to read a file line by line and store it into a variable.
7. Write a Python program to read a file line by line and store it into an array.
1. Write Python programs to draw an image, to examine its width and height, to return a tuple of the
RGB values at the given coordinates, to replace an RGB value at a given position in the imageand
to save the image.
2. Write Python programs to rotate an image, to convert an image from color to grayscale and to
convert an image from color to black and white.
3. Write Python programs to blur all or part of an image and to sharpen all or part of an image.