Python Lab
Python Lab
PREREQUISITE
None
COURSE OBJECTIVE(s)
Page 1 of 6
COURSE ASSESSMENT (Please keep the relevant components only)
The Course Assessment (culminating to the final grade), will be made up of the following
three components;
S. No. Component Weightage
a) Weekly Submissions/assignments 20%
b) Mid-term examination 30%
c) End Semester Examination 50%
Programs:
Week 1:
a. Read a list of numbers and write a program to check whether a particular element is
present or not using membership operators.
b. Read your name and age and write a program to display the year in which you will turn 100
years old.
c. Read radius and height of a cone and write a program to find the volume of a cone.
d. Write a program to compute distance between two points taking input from the user
(Hint: use Pythagorean theorem)
Week 2:
a. Read your email id and write a program to display the no of vowels, consonants, digits
and white spaces in it using if…elif…else statement.
b. Write a program to create and display a dictionary by storing the antonyms of words.
Find the antonym of a particular word given by the user from the dictionary using while
loop.
c. In number theory, an abundant number or excessive number is a number for which the
sum of its proper divisors is greater than the number itself. Write a program to find out, if
the given number is abundant. (Input: 12, Sum of divisors of 12 = 1 + 2 + 3 + 4 + 6 = 16, sum
of divisors 16 > original number 12)
Week 3:
Page 2 of 6
a. Read a list of numbers and print the numbers divisible by x but not by y (Assume x = 4 and y
= 5).
b. Read a list of numbers and print the sum of odd integers and even integers from the list.
(Ex: [23, 10, 15, 14, 63], odd numbers sum = 101, even numbers sum = 24)
c. Read a list of numbers and print numbers present in odd index position. (Ex: [10, 25, 30,
47, 56, 84, 96], The numbers in odd index position: 25 47 84).
d. Read a list of numbers and remove the duplicate numbers from it. (Ex: Enter a list with
duplicate elements: 10 20 40 10 50 30 20 10 80, The unique list is: [10, 20, 30, 40, 50, 80])
Week 4:
a. Given a list of tuples. Write a program to find tuples which have all elements divisible by K
from a list of tuples. test_list = [(6, 24, 12), (60, 12, 6), (12, 18, 21)], K = 6, Output : [(6, 24,
12), (60, 12, 6)]
b. Given a list of tuples. Write a program to filter all uppercase characters tuples from given
list of tuples. (Input: test_list = [(“GFG”, “IS”, “BEST”), (“GFg”, “AVERAGE”), (“GfG”, ),
(“Gfg”, “CS”)], Output : [(„GFG‟, „IS‟,
„BEST‟)]).
c. Given a tuple and a list as input, write a program to count the occurrences of all items
of the list in the tuple. (Input : tuple = ('a', 'a', 'c', 'b', 'd'), list = ['a', 'b'], Output : 3)
Week 5:
a. Write a program to generate and print a dictionary that contains a number (between 1
and n) in the form (x, x*x).
b. Write a program to perform union, intersection and difference using Set A and Set B.
c. Write a program to count number of vowels using sets in given string (Input : “Hello
World”, Output: No. of vowels : 3)
d. Write a program to form concatenated string by taking uncommon characters from two
strings using set concept (Input : S1 = "aacdb", S2 = "gafd", Output : "cbgf").
Week 6:
a. Write a program to do the following operations:
i. Create a empty dictionary with dict() method
ii. Add elements one at a time
iii. Update existing key‟s value
iv. Access an element using a key and also get() method
v. Deleting a key value using del() method
b. Write a program to create a dictionary and apply the following methods:
i. pop() method
ii. popitem() method
iii. clear() method
c. Given a dictionary, write a program to find the sum of all items in the dictionary.
d. Write a program to merge two dictionaries using update() method.
Page 3 of 6
Week 7:
a. Given a string, write a program to check if the string is symmetrical and palindrome or
not. A string is said to be symmetrical if both the halves of the string are the same and a
string is said to be a palindrome string if one half of the string is the reverse of the other
half or if a string appears same when read forward or backward.
b. Write a program to read a string and count the number of vowel letters and print all letters
except 'e' and 's'.
c. Write a program to read a line of text and remove the initial word from given text. (Hint:
Use split() method, Input : India is my country. Output : is my country)
d. Write a program to read a string and count how many times each letter appears.
(Histogram).
Week 8:
a. A generator is a function that produces a sequence of results instead of a single
value. Write a generator function for Fibonacci numbers up to n.
b. Write a function merge_dict(dict1, dict2) to merge two Python dictionaries.
c. Write a fact() function to compute the factorial of a given positive number.
d. Given a list of n elements, write a linear_search() function to search a given element x in a
list.
Week 9:
a. Write a program to demonstrate the working of built-in statistical functions
mean(), mode(), median() by importing statistics library.
b. Write a program to demonstrate the working of built-in trignometric functions
sin(), cos(), tan(), hypot(), degrees(), radians() by importing math module.
c. Write a program to demonstrate the working of built-in Logarithmic and Power
functions exp(), log(), log2(), log10(), pow() by importing math module.
d. Write a program to demonstrate the working of built-in numeric functions ceil(), floor(),
fabs(), factorial(), gcd() by importing math module.
Week 10:
a. Write a program to create a BankAccount class. Your class should support the following
methods for
i)Deposit
Withdraw
ii)
GetBalanace
iii)
Page 4 of 6
PinChange
iv)
b. Create a SavingsAccount class that behaves just like a BankAccount, but also has an
interest rate and a method that increases the balance by the appropriate amount of
interest (Hint:use Inheritance).
c. Write a program to create an employee class and store the employee name, id, age, and
salary using the constructor. Display the employee details by invoking
employee_info() method and also using dictionary ( dict ).
d. Access modifiers in Python are used to modify the default scope of variables. Write a
program to demonstrate the 3 types of access modifiers: public, private and protected.
Week 11:
a. Write a program to find the maximum and minimum K elements in Tuple using
slicing and sorted() method (Input: test_tup = (3, 7, 1, 18, 9), k = 2, Output: (3, 1, 9, 18))
b. Write a program to find the size of a tuple using getsizeof() method from sys module
and built-in sizeof () method.
c. Write a program to check if a substring is present in a given string or not.
d. Write a program to find the length of a string using various methods:
i. Using len() method
ii. Using for loop and in operator
iii. Using while loop and slicing
Week 12:
1. Write a program to read a filename from the user, open the file (say
firstFile.txt) and then perform the following operations:
i. Count the sentences in the file.
ii. Count the words in the file.
iii. Count the characters in the file.
2. Create a new file (Hello.txt) and copy the text to other file called target.txt. The
target.txt file should store only lower case alphabets and display the number of lines
copied.
Write a Python program to store N students records containing name, roll number and
branch. Print the given branch student’s details only.
Page 5 of 6
1. Core Python Applications Programming: Wesley J. Chun, Pearson Education, 2016.
2. Introduction to Computer Science using Python: Charles Dierbach, Wiley, 2015.
3. Python for Programmers: Paul J. Deitel, Harvey Deitel , Pearson, 2020
4. Learning Python: Mark Lutz, Orelly Publication, 2013
5. Python Programming: An Introduction to Computer Science: John Zelle, Course
Technology Cengage Learning Publications, 2013.
Page 6 of 6