ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print('%.2e' % 0.000123456, '%G' % 1e-5, '%g' % 1e-5, '%.3g' % 1234.5)- A. 1.23e-04 1E-05 1e-05 1.2e+03
- B. 1.23e-04 1E-05 1e-05 1234.5
- C. 1.23e-04 1E-05 1e-05 1.23e+03
- D. 1.2e-04 1E-05 1e-05 1.23e+03
Correct answer: C. 1.23e-04 1E-05 1e-05 1.23e+03
%g switches to exponent form when the exponent is below -4 or at least the precision, so 1234.5 with .3g becomes 1.23e+03. %G is the same as %g but uses an upper-case E.
More Python Programming questions
- What is printed? python print(max(3, 3.0), min(3.0, 3), max([2, 2.0]), type(max(2.0, 2)).name)
- What is printed? python print(sum([True, True, False]), sum([1.5, True]), True 3 + 0.5, sum([1, 2], 10))
- What is printed? python print(all([]), any([]), all([0, 1]), any([0.0, '']), all(x > 0 for x in [1, -1]))
- What is printed? python print(list(zip('ab', [1, 2, 3])), dict(zip('ab', [1, 2, 3])))
- What is printed? python print(sorted([('b', 1), ('a', 2), ('a', 1)])[1:], sorted({3: 'c', 1: 'a'}.items()))
- What is printed? python print(sorted({'b': 1, 'a': 2}), sorted({'b': 1, 'a': 2}.values(), reverse=True))