ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 1e-5, '%G' % 1e-10)- A. 0.000123 1.23e+05 1e-05 1E-10
- B. 0.000123 1.23e+05 1e-5 1E-10
- C. 0.000123 123000 1e-05 1E-10
- D. 0.00012 1.23e+05 1e-05 1E-10
Correct answer: A. 0.000123 1.23e+05 1e-05 1E-10
%.3g keeps three significant digits and switches to exponent form for large values. %g uses exponent form for small numbers below 1e-4, and %G does the same with an uppercase E.
More Python Programming questions
- What is printed? python print(max([1, 2], [1, 2, 0]) == [1, 2, 0], min((1, 'a'), (1, 'b')), sorted([(1, 'b'), (1, 'a')])[0][1])
- What is printed? python print(3 [0] == [0, 0, 0], [0] 3 is [0] 3, 'a' in 'abc' in 'abcdef')
- What is printed? python print(sum([1, 2, 3]) / 2 // 1, 7 // 2 / 2, divmod(7.0, 2)[0] == 7 // 2)
- What is printed? python print('{:^6}'.format('ab'), '{:<4}'.format(1), '{:>3}|{:<3}|'.format('a', 'b'))
- What is printed? python print('a' < 'b' < 'c', 'b' > 'a' and 'b' > 'c')
- What is printed? python print(len([range(3), 'ab']), ['ab', [1]], {{'a': 1}, 'a': 2})