22it602 - Python Programming - Cia 2 - QB
22it602 - Python Programming - Cia 2 - QB
PART A
1 Compare and contrast mutable and immutable data types in Python
7 Given is a nested tuple. tuple1 = (11, [22, 33], 44, 55). Write a program to modify the item (22) to 222
8 Indicate the method to randomize the items of a list in place using Python.
9 Infer how the finally block works in exception handling and its use in resource management.
16 When are the following exceptions raised? IndexError, KeyError, ValueError, TypeError.
17 Write a function named factors that takes an integer and returns a list of its factors.
18 Write a Python function that takes “Hello World!” as input and returns the string with all vowels removed.
PART B
1 Analyze on the different types of exception and how to handle them in Python.
Build a python program that simulates a library management system with following Specification. Each book in
the library is represented by a Array containing the book's title, author, and availability status You are provided
with a list of dictionaries where each Array represents a book.
2
The program should support the following operations:
•Display all available books.
•Borrow a book by tle. Return a book by tle.
Construct a Python program which will return the sum of the numbers in the array, returning 0 for an empty
array. Except the number 13 is very unlucky, so it does not count and number that come immediately after 13
3
also do not count.
Example : [1, 2, 3, 4] = 10 [1, 2, 3, 4, 13] = 10 [13, 1, 2, 3, 13] = 5
Construct a source code using python that creates two sets – squares and cubes in range 1-20. Demonstrate
4 the use of update (), pop (), remove (), clear () and add ()
functions for the created sets.
Develop a dictionary named students for 5 different students that contain values as follows:
Sample:{name:’Dinesh’,id:102,dept: ‘Mech’ , grade: 9}
Perform the following tasks:
a)Get the value of a key in dictionary
5 b)Get all items in the dictionary
c)Get all keys in the dictionary
d)Get all items in the dictionary
e)Calculate the total marks of the entire student in the dictionary.
f) Check if the dictionary has a key.
Given an array A with dimensions n × m, perform the following operations without using NumPy methods:
A = [[3,4,3],[2,2,5],[8,1,4]]
i)Find the indices of the [k1 × k2] element a er sor ng A.
6 ii)Write Python code to compute the average and median values of A.
iii)Choose an appropriate method to find the inverse of matrix A and concatenate it with the original matrix
A.
Write Python code to iterate through A and identify any element that is divisible by 2 and less than 5.
Given two lists, l1 and l2, write a program to create a third list l3 by picking an odd-index element from the list
7 l1 and even index elements from the list l2.
Given: l1 = [3, 6, 9, 12, 15, 18, 21] l2 = [4, 8, 12, 16, 20, 24, 28] Expected Output: [6, 12, 18, 4, 12, 20, 28]
Given two lists, l1 and l2, write a program to create a third list l3 by picking an odd-index element from the list
l1 and even index elements from the list l2.
8 For example,l1 = [3, 6, 9, 12, 15, 18, 21]
and l2 = [4, 8, 12, 16, 20, 24, 28], then output is
[6, 12, 18, 4, 12, 20, 28]
Illustrate in detail about Python Files, its types, functions and operations that can be performed on files with
9
examples.
Write a program to calculate the parking charges of a vehicle. Enter the type of vehicle as a character (like c for
car, b for bus, etc.) and a number of hours, then calculate charges as given below.
Truck – Rs.30/hour
10
Bus – Rs.20/hour
Car – Rs.10/hour
Two-wheeler – Rs.5 / hour