ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
print('%d' % 3.9, '%d' % -3.9, '%.0f' % 0.5, '%i' % True)- A. 3 -4 0 1
- B. 3 -3 0 1
- C. 3 -3 1 1
- D. 3 -3 0 True
Correct answer: B. 3 -3 0 1
%d truncates a float toward zero, so 3.9 gives 3 and -3.9 gives -3. %.0f rounds 0.5 to the even value 0, and %i formats True as 1 because bool is a subclass of int.
More Python Programming questions
- What is printed? python s = 'héllo' print(s[1], s.encode('latin-1')[1], len(s.encode('utf-16-le')), s.isascii())
- What is printed? python from decimal import Decimal, getcontext getcontext().prec = 4 print(Decimal(1) / Decimal(3), Decimal('1.10') ==…
- What is printed? python print(sorted([(2, 'b'), (1, 'z'), (2, 'a')], reverse=True))
- What is printed? python print(7 / 2 // 1, 7 // 2 / 1, -7 / 2 // 1, 7 % 2.5)
- What is printed? python print('abc'.find(''), 'abc'.count(''), ''.split(), ''.split(','))
- What is printed? python from fractions import Fraction print(Fraction(1, 3) == 1/3, Fraction(1, 3) == Fraction('0.3333333333333333')…