ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
from fractions import Fraction print(Fraction(7, 3) > 2, float(Fraction(7, 3)), Fraction(7, 3) // 1, Fraction(-7, 3) // 1)
- A. True 2.33 2 -2
- B. False 2.3333333333333335 2 -3
- C. True 2.3333333333333335 2 -3
- D. True 2.3333333333333335 3 -3
Correct answer: C. True 2.3333333333333335 2 -3
7/3 is greater than 2, and float() rounds it to the nearest double. Floor division of a Fraction by 1 gives the integer floor, which is 2 here and -3 for -7/3.
More Python Programming questions
- What is printed? python print(1 + 2 3 2 // 4 % 5, (1 + 2) 3 2 // 4 % 5, -2 2, (-2) 2)
- What is printed? python print(max('zebra', 'Zebra'), min('zebra', 'Zebra'), 'apple' > 'Apple', 'Z' < 'a')
- What is printed? python x = 5 print(x.add(3), (5).mod(-3), (-5).mod(3), int.floordiv(-5, 3))
- What is printed? python print('ab'.rjust(5, ''), 'ab'.ljust(5, '-'), 'ab'.center(5, '.'), 'ab'.center(6, '.'))
- What is printed? python print(f'{"x"!r}', '%s and %r' % ('x', 'x'), '{!s} {!r}'.format('x', 'x'))
- What is printed? python s = 'abc' print(s 2 == 'abcabc', s[1:] + s[:1], s[-1:] + s[:-1], len('ab' 0))