ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
try:
print(int(''))
except ValueError:
print('empty')
try:
print(0.0 / 0)
except ZeroDivisionError:
print('zero')- A. zero empty
- B. empty zero
- C. empty nan
- D. empty inf
Correct answer: B. empty zero
int('') raises ValueError, and the first handler prints empty. Dividing a float by zero raises ZeroDivisionError rather than giving nan or inf, so the second handler prints zero.
More Python Programming questions
- What is printed? python import math try: print(math.sqrt(-1)) except ValueError: print('domain') print(float('nan') 0, math.pow(0, 0))
- What is printed? python print('{:e}'.format(1234.5), '{:.3g}'.format(1234567), '{:g}'.format(0.0001), '{:g}'.format(0.00001))
- What is printed? python print('é'.encode('ascii', 'replace'), 'é'.encode('ascii', 'ignore'), b'hxc3xa9llo'.decode('ascii', 'ignore')…
- What is printed? python print(10 50 // 3 20 % 100, len(bin(10 50)) - 2, (10 50).bitlength())
- What is printed? python print(1 < 2 < 3 == 3.0 != 4, 1 < 2 > 3, (1 < 2) > 3, 'a' < 'b' < 'a')
- What is printed? python x = 0b1011 print(x & ~(1 << 1), x ^ (1 << 2), x | (1 << 4), (x >> 1) & 1)