16. Find the output :
count = 1
def doThis():
global count
for i in (1, 2, 3):
count += 1
doThis()
print (count)
a. 4
b. 3
c. 2
d. 0
View Answer
Ans. A
Explanation : Here the loop will execute 3 times i.e i=1,i=2,i=3. In each iteration, count is incremented by 1.
17. Find the output :
class student:
def __init__(self):
self.marks = 97
self.__cgpa = 8.7
def display(self):
print(self.marks)
obj=student()
print(obj._student__cgpa)
a. The program runs fine and 8.7 is printed
b. Error because private class members can’t be accessed
c. Error because the proper syntax for name mangling hasn’t been implemented
d. The program runs fine but nothing is printed
View Answer
Ans. a
Explanation : No issues with the code. It will work fine.
18. Find the output :
def procedural(val1):
try:
sum1=0
for item in str(val1):
sum1+=int(item_val)
except TypeError:
print("Type error occurred")
finally:
print("Finally in function")
print("Function executed successfully")
try:
procedural(792)
print("Try handled")
except ValueError:
print("Value error occurred")
except NameError:
print("Name error occurred")
finally:
print("Finally in main")
a.
Finally in function
Value error occurred
Finally in main
Try handled
b.
Finally in function
Value error occurred
Function executed successfully
Finally in main
Try handled
c.
Finally in function
Name error occurred
Finally in main
d.
Finally in function
Value error occurred
Name error occurred
Try handled
View Answer
Ans. c
Explanation : Finally block is executed irrespective of whether exception occurred or not.
19. USES Relationship is known as
a. Composition
b. Association
c. Specialization
d. Generalization
View Answer
Ans. b
Explanation : Association is relation between two separate classes which establishes through their Objects.
20. Find the output :
print('ab cd-ef'.title())
a. Ab cd-ef
b. Ab Cd-ef
c. Ab Cd-Ef
d. None of the mentioned
View Answer
Ans. c
Explanation : title() : This method returns a string where the first character in every word is upper case. Like a header, or a title.