462 Question Paper-1

You might also like

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. Winter 2017 – 18 Examination
Semester: 4 Date-13-01-2018
Subject Code: 03105255 Time: 10.30am to 01.00pm
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 (15)


1. Give the output of following Python code:
str1 = ‘This is Pyhton’
print "Slice of String : ", str1[1 : 4 : 1]
print "Slice of String : ", str1[0 : -1 : 2]
2. Is tuple mutable? Demonstrate any two methods of tuple.
3. Explain Indentation in Python.
4. Explain Comments in Python.
5. Which of the following best describes inheritance?
a) Ability of a class to derive members of another class as a part of its own definition
b) Bundling instance variables and methods in order to restrict access to certain class members
c) Focuses on variables and passing of variables to functions
d) Allows for implementation of elegant software that is well designed and easily modified
6. What is the output of the code shown below?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)

a) [‘ab’, ‘cd’]. b) [‘AB’, ‘CD’] c) [None, None] d) none of the mentioned


7. Explain constructor with respect to Object Oriented programming in Python.
8. What is the output of the code shown below?
class test:
def __init__(self,a):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()

a) Runs normally, doesn’t display anything


b)Displays 0, which is the automatic default value
c)Error as one argument is required while creating the object
d)Error as display function requires additional argument
9. Which of the following is not a valid attribute of a file object (fp)?
a) fp.name b) fp.closed c) fp.mode d) fp.size
10. How do you rename a file?
a) fp.name = ‘new_name.txt’
b) os.rename(existing_name, new_name)
c) os.rename(fp, new_name)
d) os.set_name(existing_name, new_name)

Page 1 of 2
11. What is the output of the code shown below?
import re
a = re.compile('[0-9]+')
print a.findall('3 trees')
a) [] b) [‘3’] c) Error d) [‘trees’]
12. Give the output of following Python code:
import re
print re.sub('morning', 'evening', 'good morning')
13. Give the output of following Python code:
x=2
for i in range(x):
x += 1
print (x)
14. Which of the following functions will return the symmetric difference between two sets, x and y?
a) x | y b) x ^ y c) x & y d) x – y
15. Demonstrate any two methods of dictionary.
Q.2 Answer the following questions. (Attempt any three) (15)
A) Write a Python program to print Fibonacci series upto n terms.
B) What is exception? Explain need of exception handling.
C) Write a Python programto create a Function to swap values of a pair of integers.
D) Briefly describe the methods of RE module.
Q.3 A) Write a Python program to implement the concept of inheritance. (07)
B) Write a program to calculate arithmetic operations. For this purpose you have to create one (08)
module “Arithmetic”, which includes all arithmetic operation. Import “Arithmetic” module in your
program for all operations.
OR
B) Explain the control structures(if,if-else,elif,for,while) used in python. (08)
Q.4 A) Write a program to count the occurrences of each word in the following sentence using dict(). (07)
the clown ran after the car and the car ran into the tent and the tent fell down on the clown and the
car
OR
A) Write a program in Python that reads a file and adds backslash (\) before every double quote it (07)
encounters. And then writes it to another file in the same folder.
For example:
If the file name is TestFile1.txt with text Jack said, “Hello Pune”. The output to the file TestFile2.txt
should be Jack said,\“Hello Pune\”.
B) List out features of Python Programming. What are the differences between C and Python? (08)

Page 2 of 2

You might also like