ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(format(1234.5678, '.2f'), format(1234.5678, '.2e'), format(0.000012345, '.3g'), format(12345.6789, ',.1f'))
- A. 1234.57 1.23e+03 0.0000123 12,345.7
- B. 1234.57 1.2e+03 1.23e-05 12,345.7
- C. 1234.57 1.23e+03 1.23e-05 12,345.7
- D. 1234.56 1.23e+03 1.23e-05 12,345.7
Correct answer: C. 1234.57 1.23e+03 1.23e-05 12,345.7
The g format switches to exponent form for values below 1e-4, so 0.000012345 shows as 1.23e-05. The comma flag adds thousands separators after the rounding.
More Python Programming questions
- What is printed? python print(str(1.0), str(1e2), str(1.5e-7), str(123456789012345678.0), str(0.1 + 0.7))
- What is printed? python print(1 / 3 3 == 1.0, 2 / 3 3 == 2.0, 10 / 3 3 == 10.0, 0.7 3 == 2.1)
- What is printed? python print(float('nan') < 1, float('nan') > 1, float('nan') != float('nan'))
- What is printed? python import math print(math.isnan(float('nan') 0), math.isinf(1e308 10), math.isfinite(-0.0), math.copysign(1, -0.0))
- What is printed on the first line? python print(min(0.0, -0.0), max(-0.0, 0.0), min(-0.0, 0.0), -0.0 < 0.0)
- What is printed? python print(sum(i (-1) i for i in range(1, 7)), (-1) 7 + 0.0, (-1.0) 2, (-2) -2)