What will be the output of the following Python code?
def f(x):
yield x+1
print("test")
yield x+2
g=f(9)A. Error
B. test
C. test
10
12
D. No output
Select an option to see the answer and solution.
What happens when '1' == 1 is executed?
A. we get a True
B. we get a False
C. an TypeError occurs
D. a ValueError occurs
Select an option to see the answer and solution.
Which of the following is not a standard exception in Python?
A. NameError
B. IOError
C. AssignmentError
D. ValueError
Select an option to see the answer and solution.
Is the following Python code valid?
try:
# Do something
except:
# Do something
finally:
# Do somethingA. no, there is no such thing as finally
B. no, finally cannot be used with except
C. no, finally must come before except
D. yes
Select an option to see the answer and solution.
What is the purpose of the except clause without specifying an exception type in a try block?
A. To catch any exception that occurs within the try block
B. To catch only specific exceptions
C. To handle syntax errors
D. To define a block
Select an option to see the answer and solution.
What is the purpose of the else clause in a try block?
A. To define the block of code that will be executed if no exception is raised
B. To raise an exception
C. To handle the exception
D. To create a function
Select an option to see the answer and solution.
Identify the type of error in the following Python codes?
Print(“Good Morning”)
print(“Good night)A. Syntax, Syntax
B. Semantic, Syntax
C. Semantic, Semantic
D. Syntax, Semantic
Select an option to see the answer and solution.
Which of the following is not a standard Python exception?
A. Error
B. ValueError
C. TypeError
D. IndexError
Select an option to see the answer and solution.
What is the purpose of the sys.exc_info() function in Python?
A. It returns information about the currently handled exception
B. It prints error messages
C. It raises an exception
D. It creates a function
Select an option to see the answer and solution.
What will be the output of the following Python code?
g = (i for i in range(5))
type(g)A. class <'loop'>
B. class <'iteration'>
C. class <'range'>
D. class <'generator'>
Select an option to see the answer and solution.
How can you catch and handle multiple exceptions in a single except block in Python?
A. By enclosing the exceptions in parentheses and separating them with commas
B. By using the multiple keyword
C. By using separate except blocks
D. By using the all keyword
Select an option to see the answer and solution.
What is the output of the following code:try: x = 10 / 0 except ZeroDivisionError: print("Error!") finally: print("Finally!")
A. Error! Finally!
B. Finally!
C. Error!
D. An error will occur
Select an option to see the answer and solution.
What will be the output of the following Python code?
def foo():
try:
print(1)
finally:
print(2)
foo()A. 1 2
B. 1
C. 2
D. none of the mentioned
Select an option to see the answer and solution.
What will be the output of the following Python code?
int('65.43')A. ImportError
B. ValueError
C. TypeError
D. NameError
Select an option to see the answer and solution.
How can you catch and handle multiple exceptions in a single except block in Python?
A. By enclosing the exceptions in parentheses and separating them with commas
B. By using the multiple keyword
C. By using separate except blocks
D. By using the all keyword
Select an option to see the answer and solution.
What is the syntax to raise an exception manually in Python?
A. raise Exception("Message")
B. throw Exception("Message")
C. throw("Message", Exception)
D. exception("Message")
Select an option to see the answer and solution.
An exception is . . . . . . . .
A. an object
B. a special function
C. a standard module
D. a module
Select an option to see the answer and solution.
What will be the output of the following Python code?
def f(x):
yield x+1
print("test")
yield x+2
g=f(10)
print(next(g))
print(next(g))A. No output
B. 11
12
C. 11
test
D. 11
Select an option to see the answer and solution.
Which of the following statements is true regarding the order of except clauses?
A. The except clauses should be ordered from more specific exceptions to more general ones
B. The order does not matter
C. The most general exception should come first
D. The most specific exception should come first
Select an option to see the answer and solution.
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))A. ValueError, NameError
B. AttributeError, ValueError
C. NameError, TypeError
D. TypeError, ValueError
Select an option to see the answer and solution.