ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print('%08.2f' % -1.5, '%+08d' % 42, '%-+5d|' % 7, '%x' % -255)- A. -0001.5 +0000042 +7 | -ff
- B. -0001.50 +0000042 +7 | -ff
- C. -0001.50 +42 +7 | -ff
- D. -0001.50 +0000042 +8 | -ff
Correct answer: B. -0001.50 +0000042 +7 | -ff
%08.2f keeps the sign first and zero-pads to eight characters. %+08d zero-pads a signed integer, and %-+5d left-aligns the signed 7 in five columns. %x on a negative number prints a minus sign and the digits.
More Python Programming questions
- What is printed? python print(2 10 == 1024, 2 10 == 1 << 10, 10 2 3, (10 2) 3)
- What is printed? python from itertools import accumulate print(list(accumulate([1, 2, 3], lambda a, b: a b)), list(accumulate('ab'…
- What is printed? python print(sorted({'b': 1, 'a': 1}.items()), list({3: 'x', 1: 'y'}), dict(zip('ab', [1, 2])), dict.fromkeys('ab', 0))
- What is printed? python print(len({1, 1.0, True, '1'}), len({'1', 1}), {1, 2} == {2.0, 1.0}, {0} == {False})
- What is printed? python print(float('1' + '0' 308) == 1e308, 10 308 > 1e308, 10 308 < 1e308)
- What is printed? python from functools import reduce print(reduce(lambda acc, ch: acc 10 + int(ch), '2024', 0), reduce(lambda acc, ch: acc…