ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(1e22, 1e21, 1e16, 1e15, 1e-5, 0.0001)
- A. 1e+22 1e+21 1e+16 1e+15 1e-05 0.0001
- B. 1e22 1e21 1e16 1000000000000000.0 1e-5 0.0001
- C. 1e+22 1e+21 1e+16 1000000000000000.0 1e-05 0.0001
- D. 1e+22 1e+21 10000000000000000.0 1000000000000000.0 1e-05 0.0001
Correct answer: C. 1e+22 1e+21 1e+16 1000000000000000.0 1e-05 0.0001
repr() uses scientific notation when the exponent is below -4 or at least 16. So 1e15 prints in full with a trailing .0, while 1e16 switches to 1e+16 and 1e-5 prints as 1e-05.
More Python Programming questions
- What is printed? python print(int(1e16 + 1), 253 + 1 == float(253 + 1), float(253 + 1) == 253)
- What is printed? python print(pow(10, 18, 7), (-3) 3 % 7, pow(-3, 3, -7), -3 3 % 7)
- What is printed? python print('%.3s|%5.1s|' % ('abcdef', 'xyz'))
- What is printed? python print('straße'.casefold() == 'strasse', 'straße'.lower() == 'strasse', 'Straße'.casefold())
- What is printed? python print('x'.removeprefix('xx'), 'hello'.removesuffix('llo'), 'abc'.removeprefix(''))
- What is printed? python print(str.maketrans('ab', 'xy', 'c'), 'abcabc'.translate(str.maketrans('ab', 'xy', 'c')))