ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(format(0.5, '.0f'), format(1.5, '.0f'), format(2.5, '.0f'), format(-0.5, '.0f'))
- A. 0 2 3 -1
- B. 0 1 2 -0
- C. 0 2 2 1
- D. 0 2 2 -0
Correct answer: D. 0 2 2 -0
Half-to-even rounding sends 0.5 to 0, 1.5 to 2 and 2.5 to 2. -0.5 rounds to a negative zero, and the format keeps its minus sign.
More Python Programming questions
- What is printed? python print('ab' 2 == 'abab', 'ab' 0 == '', 'a' 2 + 'b' 0 == 'aa', ('x' 2).count('xx'))
- What is printed? python print(int('٣٣') 2, '٣٣'.isdigit(), '٣٣'.isascii(), '3' == '٣')
- What is printed? python import math print(math.gcd(0, -5), math.gcd(-4, -6), math.lcm(0, 5), math.lcm(-4, 6))
- What is printed? python print(len('%.3f' % 260), '%.3f' % 260, '%.0f' % 1e20)
- What is printed? python print(round(1e16 + 2), round(9.5), round(10.5), round(-9.5))
- What is printed? python print(type(1 / 2).name, type(1 // 2).name, type(2 -1).name, type(2 0.5).name, type(True + 1).name)