Python Questionaire
Python Questionaire
1. What will be the output of the following 4. What will be the output of the following
code snippet? code snippet?
class Sales: class A:
def __init__(self, id): def __init__(self):
self.id = id self.calcI(30)
id = 100 print("i from A is", self.i)
val = Sales(123)
print (val.id) def calcI(self, i):
self.i = 2 * i;
A. SyntaxError, this program will not run
B. 100 class B(A):
C. 123 def __init__(self):
D. None of the above super().__init__()
1
ASSESSMENT : PYTHON & DBMS
D. The __init__ method of class A gets GFG
invoked and it displays “i from B is 90”.
9. What is the output of the following
6. Predict the output of the following piece of program?
code. dictionary1 = {'Google' : 1,
dictionary = {} 'Facebook' : 2,
dictionary[1] = 1 'Microsoft' : 3
dictionary['1'] = 2 }
dictionary[1] += 1 dictionary2 = {'GFG' : 1,
sum = 0 'Microsoft' : 2,
for k in dictionary: 'Youtube' : 3
sum += dictionary[k] }
print sum dictionary1.update(dictionary2);
for key, values in dictionary1.items():
7. Predict the output of the following code. print(key, values)
check1 = ['Learn', 'Quiz', 'Practice',
'Contribute'] a) Compilation error b) Runtime error
check2 = check1 c) (‘Google’, 1)
check3 = check1[:] (‘Facebook’, 2)
(‘Youtube’, 3)
check2[0] = 'Code' (‘Microsoft’, 2)
check3[1] = 'Mcq' (‘GFG’, 1)
d) None of these
count = 0
for c in (check1, check2, check3): 10. What is the output of the following
if c[0] == 'Code': program?
count += 1
if c[1] == 'Mcq': from math import sqrt
count += 10 L1 = [x**2 for x in range(10)].pop()
L1 + = 19
print count print(sqrt(L1), end = " ")
L1 = [x**2 for x in reversed(range(10))].pop()
8. What is the output of the following L1 + = 16
program? print(int(sqrt(L1)))
2
ASSESSMENT : PYTHON & DBMS
12. What is the output of the following a) No error b) Assertion error c)
program? Input output error
data = 50 d) Name error
try:
data = data/0 15. What will be the output of the following
except ZeroDivisionError: Python code?
print('Cannot divide by 0 ', end = '') class A:
else: def __init__(self,x):
print('Division successful ', end = '') self.x = x
def count(self,x):
try: self.x = self.x+1
data = data/5
except: class B(A):
print('Inside except block ', end = '') def __init__(self, y=0):
else: A.__init__(self, 3)
print('GFG', end = '') self.y = y
def count(self):
a) Cannot divide by 0 GFG self.y += 1
b) Cannot divide by 0
c) Cannot divide by 0 Inside except block GFG def main():
d) Cannot divide by 0 Inside except block obj = B()
obj.count()
13. What will be the output of the following print(obj.x, obj.y)
Python code?
main()
class student:
def __init__(self): a) 3 0 b) 3 1 c) 0 1 d) An exception in
self.marks = 97 thrown
self.__cgpa = 8.7
def display(self): 16. What will be the output of the following
print(self.marks) Python code?
obj=student() s1={3, 4}
print(obj._student__cgpa) s2={1, 2}
s3=set()
a) The program runs fine and 8.7 is printed i=0
b) Error because private class members can’t j=0
be accessed for i in s1:
c) Error because the proper syntax for name for j in s2:
mangling hasn’t been implemented s3.add((i,j))
d) The program runs fine but nothing is i+=1
printed j+=1
print(s3)
14. What happens if the file is not found in
the following Python code? a) {(3, 4), (1, 2)} b) Error
c) {(4, 2), (3, 1), (4, 1), (5, 2)} d) {(3, 1), (4,
a=False 2)}
while not a:
try: Sample Table – Worker
f_n = input("Enter file name") WORK FIRST_N LAST_N SALARY JOINING_DA DEPART
ER_ID AME AME TE MENT
i_f = open(f_n, 'r')
except: 001 Monika Arora 100000 2014-02-20 HR
09:00:00
print("Input file not found")
002 Niharika Verma 80000 2014-06-11 Admin
09:00:00
3
ASSESSMENT : PYTHON & DBMS
003 Vishal Singhal 300000 2014-02-20 HR 19. Write an SQL query to print details of the
09:00:00 Workers whose FIRST_NAME ends with ‘h’
004 Amitabh Singh 500000 2014-02-20 Admin and contains six alphabets.
09:00:00
005 Vivek Bhati 500000 2014-06-11 Admin 20. Write an SQL query to print details of the
09:00:00
Workers who have joined in Feb’2014.
006 Vipul Diwan 200000 2014-06-11 Account
09:00:00
21. Write an SQL query to print details of the
007 Satish Kumar 75000 2014-01-20 Account Workers who are also Managers.
09:00:00
008 Geetika Chauhan 90000 2014-04-11 Admin
09:00:00
1 Manager 2016-02-20
00:00:00
2 Executive 2016-06-11
00:00:00
8 Executive 2016-06-11
00:00:00
5 Manager 2016-06-11
00:00:00
4 Asst. 2016-06-11
Manager 00:00:00
7 Executive 2016-06-11
00:00:00
6 Lead 2016-06-11
00:00:00
3 Lead 2016-06-11
00:00:00