ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(sorted([0.5, 1, True, False]), max(0.5, 1, True))
- A. [False, 0.5, True, 1] True
- B. [False, 0.5, 1, True] 1
- C. [False, 0.5, 1, True] True
- D. [0.5, False, 1, True] 1
Correct answer: B. [False, 0.5, 1, True] 1
False is 0 and is the smallest. 1 and True compare equal, so sorted keeps their input order, and max returns the first of equal maxima, which is 1.
More Python Programming questions
- What is printed? python print('%s|%s' % ('a', 'b'), 'ok', '%5.1f%%' % 99.55)
- What is printed? python print(len(set('aabbcc')), sorted(set('cba')), 'abc'.index('b') + 'abc'.count('b'))
- What is printed? python print(1000000 1000000 == 1012, 0.1 0.1 100 == 1, round(0.1 0.1 100, 10) == 1.0, 2 0.5 == 2 (1 / 2))
- What is printed? python print(sum(range(0, 101, 5)), len(range(0, 101, 5)))
- What is printed? python print(bin(37)[2:].zfill(8), int('100101', 2) == 37)
- What is printed? python import heapq h = [] for x in [5, 2, 8]: heapq.heappush(h, x) print(heapq.heappop(h), heapq.heappop(h), h)