Python - 04-10-22

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Seat No: ______________ Enrollment No: ____________________

PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
B.Tech. Summer 2022 - 23 Examination
Semester: 8 Date: 04/10/2022
Subject Code: 203105467 Time: 2:00pm to 4:30pm
Subject Name: Python Programming Total Marks: 60

Instructions:
1. All questions are compulsory.
2. Figures to the right indicate full marks.
3. Make suitable assumptions wherever necessary.
4. Start new question on new page.

Q.1 Objective Type Questions - (Each of one mark) (15)


1. Find output of following Python code:

list1 = ['physics', 'chemistry', 1997, 2000]


list2 = [1, 2, 3, 4, 5, 6, 7]
print "list1[0]: ", list1[-2] #statement 1
print "list2[1:5]: ", list2[1:5] #statement 2

2. NumPY stands for?


a) Numbering Python b) Number in Python c) Numerical Python d) None
3. What is the use of tail() method in Pandas?
4. Accept only numbers lower than 5 using list comprehension.
5. What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
a) NameError b) ValueError
c) IndexError d) TypeError
6. Overriding means changing behaviour of methods of derived class methods in the base class.
(True/False).
7. A Python list can hold a mixture of integers and strings (True/False).
8. What do we use to define a block of code in Python language?
a) Key
b) Brackets
c) Indentation
d) None of these
9. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
10. What will be the output of the following program?

tuple = {}
tuple[(1,2,4)] = 8
tuple[(4,2,1)] = 10
tuple[(1,2)] = 12
_sum = 0
for k in tuple:
_sum += tuple[k]
print(len(tuple) + _sum)

a) 34 b) 12
c) 31 d) 33

Page 1 of 2
11. What is a python library that can be used to send and receive data over HTTP?
12. Which of the following options can be used to read the first line of a text file data.txt?
a) f = open(‘data.txt’); f.read()
b) f = open(‘data.txt’,’r’); f.read(n)
c) myfile = open(‘data.txt’); f.readline()
d) f = open(‘data.txt’); f.readlines()
13. ______ represents an entity in the real world with its identity and behavior.
14. ______ command helps us to reset the pen (turtle).
15. What is delattr(obj,name) used for?
Q.2 Answer the following questions. (Attempt any three) (15)
A) What are the key features of Python?
B) What are python modules? Name some commonly used built-in modules in Python? Explain use
of anyone of the modules using example.
C) Explain the following python regular expression function with an example: findall(), split() and
search().
D) Write a python program to implement Fibonacci series of n elements.
Q.3 A) Is String a mutable data type? Also explain the string operations length, indexing and slicing in (07)
detail with an appropriate example.
B) Write a python program that sorts the list [34, 25, 81, 12, 5] using merge sort. (08)
OR
B) Create a Python program to read a text file and do following: (08)
1. Print no. of lines
2. Print no. of unique words
3. Count the frequency of words in a file
4. Find the longest words
Q.4 A) Which are the OOP concepts of class? Explain any one of them using a Python Example. (07)
OR
A) Write a python program to get an output like the below image. (07)

B) Write a python program to implement linear search and binary search. (08)

Page 2 of 2

You might also like