ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
from fractions import Fraction
print(Fraction('1.5'), Fraction('3/6'), float(Fraction('1/3')) == 1/3, str(Fraction(2, 4)))- A. 3/2 1/2 False 2/4
- B. 3/2 3/6 True 1/2
- C. 3/2 1/2 True 2/4
- D. 3/2 1/2 True 1/2
Correct answer: D. 3/2 1/2 True 1/2
Fraction reduces to lowest terms, so 1.5 is 3/2, 3/6 is 1/2 and 2/4 becomes 1/2. float(Fraction('1/3')) rounds to the same double as 1/3.
More Python Programming questions
- What is printed? python print(sum([[1, 2], [3]], []), ''.join(['ab', 'c']), [x for x in 'hey'][::2])
- What is printed? python print('%o' % 8 == oct(8)[2:], '%x' % 255 == hex(255)[2:], bin(5)[2:].zfill(4))
- What is printed? python print(-1 2, (-1) 2, -1 -1, (-1) -1)
- What is printed? python print(divmod(-9, 4), divmod(9, -4), -9 % 4, 9 % -4)
- What is printed? python class C: k = 10 try: a = [k + x for x in range(3)] except NameError: a = 'NameError' print(C.a)
- What is printed? python a = [1, 2, 3, 4] a[1:3] = [9] print(a) b = [1, 2, 3, 4] try: b[::2] = [0] except ValueError: print('ValueError')