ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 0.5)- A. 0.000123 1.23e+05 0.5
- B. 0.000123 123000 0.5
- C. 0.0001234 1.23e+05 0.5
- D. 0.000123 1.23e+05 0.50
Correct answer: A. 0.000123 1.23e+05 0.5
%g uses scientific notation when the exponent is below -4 or at least the precision, so 123456.0 becomes 1.23e+05. 0.0001234 has exponent -4, which still prints in fixed form with three significant digits.
More Python Programming questions
- What is printed? python print(max('7', '10'), max(7, 10), min('7', '10'), '7' > '10')
- What is printed? python print(len(f'{3.5:>8.2f}'), f'{-3.5:08.1f}', f'{12:#06x}', f'{7:+05d}')
- What is printed? python print('abc'.encode() == b'abc', b'abc'.decode() == 'abc', 'é'.encode('utf-8') == b'xc3xa9', len(b'xc3xa9'.decode()))
- What is printed? python print('%.3s' % 'abcdef' + '|' + '%-4d|' % 7 + '%04.1f' % 2.25)
- What is printed? python x = 0xFF print(x >> 4, x & 0xF0, x ^ 0x0F, ~x & 0xFF)
- What is printed? python print(int.frombytes((65).tobytes(1, 'big') 3, 'big'), 65 65 65, bytes([65] 3).decode())