U23cs382 Am24
U23cs382 Am24
Second Semester
B.E. – Computer Science and Engineering
(Common to B.E. – ECE, CCE and B.Tech. – IT, CSBS)
U23CS382 – Python Programming
(Regulations 2023)
Page 1 of 4
SECE/CoE/QPT/002/Rev. 00/03.05.2022
6. Write a Python program to read first n lines of a file. 2 CO3 K2
7. Illustrate the use of constructor in Python 2 CO4 K1
8. Compare SQL and Mongodb. 2 CO4 K2
9. Differentiate Line Plot and Bar Plot in Python. 2 CO5 K2
10. List steps to fill missing data in Python. 2 CO5 K1
Part B – (5 X 16 = 80 Marks)
11 a) (i) List Python operators and their associativity and precedence. 8 CO1 K2
(ii) Write a Python program to calculate a dog's age in dog 8 CO1 K3
years.
Note: For the first two years, a dog year is equal to 10.5
human years. After that, each dog year equals 4 human
years.
Expected Output:
Input a dog's age in human years: 15
The dog's age in dog's years is 73
(Or)
11 b) (i) Write a Python program to construct the following pattern, 8 CO1 K3
using a nested for loop.
*
**
***
****
*****
****
***
**
*
(ii) Explain the difference between mutable and immutable data 8 CO1 K2
types in Python. Give examples of each and discuss why
mutability is important in programming.
12 a) (i) Write a Python program to find items starting with a specific 8 CO2 K3
character from a list.
Expected Output:
Original list:
Page 2 of 4
SECE/CoE/QPT/002/Rev. 00/03.05.2022
['abcd', 'abc', 'bcd', 'bkie', 'cder', 'cdsw', 'sdfsd', 'dagfa',
'acjd']
Items start with a from the said list:
['abcd', 'abc', 'acjd']
Items start with d from the said list:
['dagfa']
Items start with w from the said list:
[]
(ii) Write a Python program to convert a given list of tuples to a 8 CO2 K3
list of lists.
Original list of tuples: [(1, 2), (2, 3), (3, 4)]
Convert the said list of tuples to a list of lists: [[1, 2], [2, 3],
[3, 4]]
Original list of tuples: [(1, 2), (2, 3, 5), (3, 4), (2, 3, 4, 2)]
Convert the said list of tuples to a list of lists: [[1, 2],
[2, 3,5], [3, 4], [2, 3, 4, 2]]
(Or)
12 b) (i) Differentiate between append() and extend() methods in 8 CO2 K2
Python lists. Provide examples to illustrate their usage.
(ii) Write a Python function that takes a dictionary as input and 8 CO2 K3
returns the keys sorted in descending order based on their
associated values.
13 a) (i) Describe the structure of a Python package and explain how 8 CO3 K2
packages differ from modules.
(ii) Write a Python program that reads a date input from the 8 CO3 K3
user in the format "YYYY-MM-DD" and print in a user-friendly
format, such as "Monday, January 1, 2023".
(Or)
13 b) (i) Write a Python program that takes a text file as input and 8 CO3 K3
returns the number of words of a given text file.
Note: Some words can be separated by a comma with no
space.
(ii) Create a package structure named my_package that 8 CO3 K3
includes multiple modules (module1.py, module2.py, etc.).
Provide an example of how to import specific modules and
functions from within the my_package package.
Page 3 of 4
SECE/CoE/QPT/002/Rev. 00/03.05.2022
14 a) (i) Develop a class Animal with a method sound() that prints a 8 CO4 K3
generic sound. Then create two subclasses, Dog and Cat,
that override the sound() method to print specific sounds for
each animal. Demonstrate polymorphism by calling the
sound() method on instances of Dog and Cat.
(ii) Illustrate how to connect to a MongoDB instance for a 8 CO4 K2
sample application
(Or)
14 b) (i) Discuss the various methods available in MongoDB for 8 CO4 K2
retrieving documents from a collection. How do queries in
MongoDB differ from traditional SQL queries?
(ii) Create an event management application using MongoDB. 8 CO4 K3
Page 4 of 4
SECE/CoE/QPT/002/Rev. 00/03.05.2022