ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(f'{-1.5:+.1f}', f'{0.5:.0f}', f'{1.5:.0f}', f'{-0.04:.1f}')- A. -1.5 0 3 0.0
- B. -1.5 1 2 -0.0
- C. -1.5 0 1 -0.0
- D. -1.5 0 2 -0.0
Correct answer: D. -1.5 0 2 -0.0
The .0f format rounds exact halves to even, so 0.5 gives 0 and 1.5 gives 2. -0.04 rounds to a negative zero at one decimal, and the format keeps the minus sign.
More Python Programming questions
- What is printed? python print(format('x', '>4') + '|' + format(3.14159, '^9.2f') + '|' + format(42, '+') + '|' + format(1234567, ','))
- What is printed? python print('%d%%' % 50, '%x' % 255, '%o' % 8, '%e' % 12345.678)
- What is printed? python print(-(264) >> 3, -(264) // 8, -(264) % 10)
- What is printed? python print('a,b,,c'.split(','), 'a b c'.split(), 'a b c'.split(' '), ' x '.strip(), 'x,'.split(','))
- What is printed? python print(sorted(['Bb', 'aA', 'bb', 'AA'], key=str.lower))
- What is printed? python print(-7 % 3, 7 % -3, -7 // 3, 7 // -3)