pm
USN BPLCK205B/ BPLCKB205
Second Semester B.E./B.Tech. Degree Examination, Nov./Dec. 2023
6
:1
Introduction to Python Programming
Time: 3 hrs. Max. Marks: 100
9
:1
Note: 1. Answer any FIVE full questions, choosing ONE full question from each module.
2. M : Marks , L: Bloom’s level , C: Course outcomes.
01
N
Module – 1 M L C
-G
Q.1 a. Demonstrate with example print( ), input( ) and format ( ). 5 L1 CO1
3
02
N
b. Explain conditional branching statements with syntax and write a suitable 7 L2 CO1
-G
program for the same.
-2
c. Write a python program to check whether a given number is Armstrong or 8 L3 CO1
N
12
not. [Hint – An Armstrong number is any number of n digits which is equal
-G
to the sum of nth power of digits in the number. For example, 371 is an
7-
Armstrong number since 3**3 + 7**3+1** 3 = 371]
N
-0
OR
-G
Q.2 a. Write a python program to guess the secret number between 1 to 25 within 8 L3 CO1
U
5 guess if the number is same then it is right guess else wrong guess.
VT
m
-G
b. What are user defined function? How can we pass the arguments to the 6 L1 CO1
6p
functions? Explain with suitable examples.
N
N
:0
c. -G
What are comparison and Boolean operators? List all the comparison and 6 L1 CO1
-G
Boolean operators in python.
50
N
N
Module – 2
:
-G
01
Q.3 a. Explain the methods of list data types in python for the following operation 8 L1 CO2
-G
with suitable code snippets for each.
i) Adding values to a list
N
N
23
ii) Removing values from a list
-G
-G
iii) Finding a value in a list
20
iv) Sorting the values in a list
N
GN
2-
-G
b. Explain the concept of list slicing and list traversing with an example. 6 L1 CO2
-1
c. What is a dictionary? Write a python program to count occurrences of 6 L3 CO2
N
characters in a string and print the count.
07
-G
OR
a. Write a python program that find the missing number from the given a list 10 L3
N
Q.4 CO2
n-1 numbers ranging from 1 to n, There are no duplicates (Hint – eg : Input
-G
= 1 2 4 6 3 7 8, output : 5)
N
b. How is triple different from list( )? Explain with example the function used 6 L1 CO2
-G
to convert list into triple and triple into list.
c. Explain insert( ) and remove( ) methods of list with example. 4 L1 CO2
N
-G
1 of 2
GN
BPLCK205B/ BPLCKB205
Module – 3
Q.5 a. Write a python program to count number of lines in a file. 5 L3 CO1
pm
b. Explain the following functions with example : 10 L1 CO1
i) makedirs( ) ii) getcwd( ) iii) velpath( ) iv) listdir( ) v) sub( )
6
:1
c. What are three “mode” arguments that can be passed to open( ) function 5 L1 CO1
with example.
9
:1
OR
Q.6 a. With code snippet, explain saving variables using the shelve module and 6 L2 CO2
01
N
print pformat( ) functions.
-G
b. Write a python program that accepts a sentence and find the number of
3
7 L3 CO2
words, digits, upper case letters and lower case letters.
02
N
-G
c. Write a program to make a new string with all the consonant eliminated
-2 7 L3 CO2
from the string read from the user [Hint – For example Input: Hello, have a
good day. Output : HII, hv gd dy]
N
12
-G
Module – 4
7-
Q.7 a. What is meant by compressing Files? Explain reading, extracting and 10 L1 CO1
creating ZIP files with an example. N
-0
-G
b. Define assertions. What does an assert statement in python consists of? 5 L1 CO2
U
VT
c. How does OS.walk( ) work in python?
m 5 L3 CO3
-G
6p
OR
Q.8 a. Discuss the basicConfig( ) method to configure the lagging with an 7 L2 CO2
N
N
:0
example. -G
-G
50
b. Write a program to depict Raising Exception. 7 L1 CO2
N
N
c. Explain the functions of Shutil module with example. 6 L2 CO2
:
-G
01
-G
Module – 5
Q.9 a. Compare the difference between class, static and instance method. 6 L2 CO4
N
N
23
-G
-G
b. Define classes and objects in python. Create a class called Employee and 9 L2 CO4
20
initialize it with employee id and name. Design method to :
N
i) Set Age – to assign age to the employee
GN
ii) Set Salary – to assign salary to the employee
2-
-G
iii) Display – to display all information of the employee.
-1
c. Explain ---- init ---- and str --- method with an example. 5 L2 CO4
07
-G
OR
Q.10 a. Write a program to implement polymorphism in python using method 7 L3 CO4
N
overriding.
-G
b. Define pure function? Give an example program that returns square of a 7 L3 CO4
passed integer.
N
How class can be instantiated in python? Write a python program to
-G
c. 6 L2 CO4
instances as return values to define a class RECTANGLE with member
width. Height cornerX cornerY and member function to find center area
N
and perimeter of a rectangle.
-G
*****
2 of 2
GN