Question 21
EasyWhat is the output of this code?
try:
print(10 // )
ZeroDivisionError:
(, end=)
:
()
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
What is the output of this code?
try:
print(10 // )
ZeroDivisionError:
(, end=)
:
()
0 end
end
div end
div
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
try:
x = int("7")
except ValueError:
print("bad")
else:
print(x * 2)
14
77
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class LowBalance(Exception):
pass
try:
raise LowBalance("too low")
except LowBalance as e:
print(e)
Error
too low
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
int main() {
try {
throw 5;
} catch (int e) {
cout << e * 2;
}
}
Compilation error
10
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
try:
[1, 2][5]
except IndexError:
print("index")
except Exception:
print("other")
Error
index other
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
int main() {
try {
throw "oops";
} catch (int) {
cout << "int";
} catch (...) {
cout << "any";
}
}
oops
Compilation error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
def f():
raise ValueError("v")
try:
f()
print("after")
except ValueError:
print("caught")
after caught
after
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
try:
print("A", end=" ")
except Exception:
print("B", end=" ")
else:
print("C", end=" ")
finally:
print("D")
A B C D
A C D
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
try:
int("abc")
except ValueError:
print("Value error caught")
except Exception:
print("Generic error caught")
Both handlers run
Generic error caught
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
int main() {
try {
throw 42;
} catch (int e) {
cout << "Caught: " << e;
}
return 0;
}
42
Terminate
Sign up free to see the answer and a step-by-step explanation.
7
bad
Exception
LowBalance
0
5
other
index
any
int
caught
v
A B D
A D
Program crashes
Value error caught
Caught: 42
Caught