Total No. of Questions : 5] SEAT No.
:
P6396 [Total No. of Pages : 3
[6155]-57
T.Y. B.Sc. (Computer Science)
CS-3510 : PYTHON PROGRAMMING
(Revised 2019 Pattern) (CBCS) (Semester - V)
Time : 2 Hours] [Max. Marks : 35
Instructions to the candidates:
1) All questions are compulsory.
2) Figures to the right indicate full marks.
3) Total number of questions are five.
Q1) Attempt any Eight of the following: [8×1=8]
a) What is indentation?
b) Write code to print the elements of the list 11 = [10, 20, 30, 40, 50]
c) What is a slice operator?
d) What is variable-length argument?
e) How to add multiple elements at the end of the list?
f) Explain the remove () method.
g) Write a lambda function to add 10 to a given integer.
h) How to raise an exception with arguments.
i) List the methods of re package.
j) What is a wb mode in file?
Q2) Attempt any four of the following: [4×2=8]
a) What is a package? Explain with example how to create a package.
b) What are the usage of tuples zip (), tuple(), count() and index() functions?
[6155]-57 1 P.T.O.
c) What is an anonymous function? How to create it? Explain with example.
d) Explain the following loops with example.
i) While
ii) For
e) How to perform input output operations? Explain with example.
Q3) Attempt any Two of the following: [2×4=8]
a) Write a program to accept a string from user and display the string in
reverse order eliminating the letter ‘s’ from the string.
b) Write a program to raise a user defined exception to check if age is less
that 18.
c) Write a Python program to check that a string contains only a certain set
of characters (in this case a-z, A-Z and 0-9).
Q4) Attempt any Two of the following: [2×4=8]
a) 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', add 'ly'
instead. If the string length of the given string is less than 3, leave it
unchanged.
b) Write a Python program to combine values in a list of dictionaries. Sample
data: [{'item': 'item 1', 'amount': 400}, {'item': 'item2', 'amount': 300},
{'item': 'item1', 'amount': 750}]
Expected Output: Counter ({'item1': 1150, 'item2': 300})
c) Write a Python program to extract year, month, date and time using
Lambda.
[6155]-57 2
Q5) Attempt any one of the following: [1×3=3]
a) Check1 = ['Learn', 'Quiz', 'Practice', 'Contribute']
Check2 = check1
Check3 = check1 [:]
Check2[0] = 'Code'
Check3[1] = 'Mcq'
Count = 0
For c in (check 1, check2 check3):
if c[0] == 'Code':
count + = 1
if c[1] == 'Mcq':
count + = 10
print (count)
b) Counter = {}
Def add To Counter (Country):
If country in counter:
Counter [country] + = 1
Else:
Counter [country] = 1
Add To Counter ('China')
Add To Counter ('Japan')
Add To Counter ('china')
Print (len(counter))
[6155]-57 3