ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(round(-1234.5, -2), round(123456.0, -3), round(0.0, 2), round(1e-7, 7))
- A. -1200.0 123000.0 0.0 1e-07
- B. -1300.0 123000.0 0.0 1e-07
- C. -1200.0 123200.0 0.0 1e-07
- D. -1200.0 123000.0 0.0 1e-7
Correct answer: A. -1200.0 123000.0 0.0 1e-07
Rounding a float to a negative number of places returns a float, so -1234.5 goes to -1200.0 and 123456.0 goes to 123000.0. Rounding 1e-7 to seven places keeps it as 1e-07 in repr.
More Python Programming questions
- What is printed? python print(str(1.0), str(1), str(1.0e0), str(10.0 0), repr(1e0))
- What is printed? python print(7 & ~1, 7 >> 1 << 1, (7 | 8) & 12, 6 ^ 3 ^ 3)
- What is printed? python print(sorted([(-1, 'a'), (1, 'b'), (-1, 'c')], key=lambda t: t[0], reverse=True))
- What is printed? python x = 'abc' y = x.upper() z = x.upper().lower() print(y, z == x, x.upper().upper() == y, len(y + z))
- What is printed? python print(int('0009'), float('009.50'), int(' -0 '), str(-0))
- What is printed? python print(len(str(2 64)), str(2 64)[:4], 2 64 % 1000)