The Sports Zones
Home
MCQs
Python — Quiz
Python Mcq Set 21
21 questions · Test your knowledge
Home
/
MCQs
/
Python Mcq Set 21
1
What will be the output of the following Python code? #generator def f(x): yield x+1 g=f(8) print(next(g))
A
8
B
9
C
7
D
Error
2
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
3
What will be the output of the following Python code? def a(): try: f(x, 4) finally: print('after f') print('after f?') a()
A
No output
B
after f?
C
error
D
after f
4
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
[0, 1, 2, 3, 4]
B
[1, 2, 3, 4, 5, 6, 7, 8]
C
[1, 2, 3, 4, 5]
D
[0, 1, 2, 3, 4, 5, 6, 7]
5
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))
A
‘list’ object is not iterator
B
‘tuple’ object is not iterator
C
‘list’ object is iterator
D
‘tuple’ object is iterator
6
Which of the following is not an exception handling keyword in Python?
A
try
B
except
C
accept
D
finally
7
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’>
8
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")
A
No error
B
Assertion error
C
Input output error
D
Name error
9
What will be the output of the following Python code? lst = [1, 2, 3] lst[3]
A
NameError
B
ValueError
C
IndexError
D
TypeError
10
What will be the output of the following Python code? t[5]
A
IndexError
B
NameError
C
TypeError
D
ValeError
11
What will be the output of the following Python code, if the time module has already been imported? 4 + '3'
A
NameError
B
IndexError
C
ValueError
D
TypeError
12
What will be the output of the following Python code? int('65.43')
A
ImportError
B
ValueError
C
TypeError
D
NameError
13
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
14
What will be the output of the following Python code? def getMonth(m): if m<1 or m>12: raise ValueError("Invalid") print(m) getMonth(6)
A
ValueError
B
Invalid
C
6
D
ValueError(“Invalidâ€)
15
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")
A
Bye (printed once)
B
No output
C
Invalid (printed once)
D
Bye (printed infinite number of times)
16
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
17
Which of the following statements is true?
A
The standard exceptions are automatically imported into Python programs
B
All raised standard exceptions must be handled in Python
C
When there is a deviation from the rules of a programming language, a semantic error is thrown
D
If any exception is thrown in try block, else block is executed
18
Which of the following is not a standard exception in Python?
A
NameError
B
IOError
C
AssignmentError
D
ValueError(“Invalidâ€)
19
An exception is _______
A
an object
B
a special function
C
a standard module
D
a module
20
_______________ exceptions are raised as a result of an error in opening a particular file.
A
ValueError
B
TypeError
C
ImportError
D
IOError
21
Which of the following blocks will be executed whether an exception is thrown or not?
A
except
B
else
C
finally
D
assert
Submit Quiz
Back to All Quizzes