Question 1 of 25
Hints left: 3
Q1
Is the following Python code valid? try: # Do something except: # Do something else: # Do something
Q2
Which built-in Python function can be used to retrieve the error message associated with an exception?
Q3
What is the purpose of the sys.exc_info() function in Python?
Q4
What is the purpose of the assert statement in Python?
Q5
Compare the following two Python codes shown below and state the output if the input entered in each case is -6? CODE 1 import math num=int(input("Enter a number of whose factorial you want to find")) print(math.factorial(num)) CODE 2 num=int(input("Enter a number of whose factorial you want to find")) print(math.factorial(num))
Q6
Which of the following statements is true?
Q7
What will be the output of the following Python code? lst = [1, 2, 3] lst[3]
Q8
The error displayed in the following Python code is? import itertools l1=(1, 2, 3) l2=[4, 5, 6] l=itertools.chain(l1, l2) print(next(l1))
Q9
What will be the output of the following Python code? try: if '1' != 1: raise "someError" else: print("someError has not occurred") except "someError": print ("someError has occurred")
Q10
What will be the output of the following Python code? t[5]
Q11
Which of the following blocks will be executed whether an exception is thrown or not?
Q12
What will be the output of the following Python code? #generator def f(x): yield x+1 g=f(8) print(next(g))
Q13
What is the purpose of the except clause without specifying an exception type in a try block?
Q14
What will be the output of the following Python code? def f(x): for i in range(5): yield i g=f(8) print(list(g))
-
A
-
B
-
C
-
D
Q15
What will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)
Q16
What will be the output of the following Python code? def a(): try: f(x, 4) finally: print('after f') print('after f?') a()
Q17
Syntax errors are also known as parsing errors.
Q18
. . . . . . . . exceptions are raised as a result of an error in opening a particular file.
Q19
How can you create a custom exception class in Python?
Q20
What will be the output of the following Python code, if the time module has already been imported? 4 + '3'
Q21
What happens if the file is not found in the following Python code? a=False while not a: try: f_n = input("Enter file name") i_f = open(f_n, 'r') except: print("Input file not found")
Q22
What will happen if an exception is raised in a try block and is not handled in any of the except blocks?
Q23
What will be the output of the following Python code? x=10 y=8 assert x>y, 'X too small'
Q24
What will be the output of the following Python code if the input entered is 6? valid = False while not valid: try: n=int(input("Enter a number")) while n%2==0: print("Bye") valid = True except ValueError: print("Invalid")
Q25
What is the purpose of the assert statement in Python?