ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len('%-8.3f|' % 3.14159), len('%08.3f' % -3.14159), '%08.3f' % -3.14159)- A. 8 8 -003.142
- B. 9 8 -003.142
- C. 9 9 -0003.142
- D. 9 8 -3.142
Correct answer: B. 9 8 -003.142
%-8.3f gives 3.142 padded to width eight, plus the bar, for nine characters. %08.3f puts the sign first and zero-pads to eight characters total.
More Python Programming questions
- What is printed? python import math print(math.prod([]), math.prod(range(1, 6)), math.lcm(range(1, 6)), math.lcm())
- What is printed? python print(list('ab') + ['c'] 2, 'ab' + 'c' 2, ('a',) 2)
- What is printed? python print(10 18 // 7 7 + 10 18 % 7 == 10 18, (-10 18) // 7 7 + (-10 18) % 7 == -10 18, -10 18 % 7 == (-10) 18 % 7)
- What is printed? python from bisect import bisectleft, bisectright a = [1, 2, 2, 2, 3] print(bisectleft(a, 2), bisectright(a, 2)…
- What is printed? python print(str(12345)[::-1], int(str(12345)[::-1]) + 1, sum(int(d) for d in str(12345)), len(str(0)))
- What is printed? python print(0o777 ^ 0o070, 0b1111 & 0xF0 | 0x0F, 1000000 // 1e3)