ProgrammingHardTCS NQT · Infosys
What is printed on the last line?
What is printed on the last line?
nums = ['10', '9', '100', '1'] print(sorted(nums)) print(sorted(nums, key=int)) print(max(nums), max(nums, key=int))
- A. 9 100
- B. 100 100
- C. 9 9
- D. 100 9
Correct answer: A. 9 100
Strings compare character by character, so '9' is the largest string. With key=int the comparison uses numeric values, so '100' wins.
More Python Programming questions
- What is printed on the third line? python print(sorted([(1, 'x'), (1, 'X'), (0, 'z')], key=lambda t: t[1].lower())) print(sorted(['b'…
- What is printed on the second line? python u = '' for ch in 'abc': u = ch + u print(u)
- What is printed on the first line? python x = 0.1 3 y = 0.3 print(abs(x - y) < 1e-9, x > y, x - y, y - x) print(float('0.1') 3 == 0.3, 3…
- What is printed on the second line? python import math print(math.isclose(1e9, 1e9 + 1e-3), math.isclose(1e9, 1e9 + 1, reltol=1e-9))…
- What is printed on the first line? python print(0.1 + 0.2 - 0.3 == 0, 0.1 + 0.2 - 0.3) print(1 - 0.9 == 0.1, 1 - 0.9)
- What is printed? python import sys print(sys.floatinfo.epsilon, 1.0 + sys.floatinfo.epsilon > 1.0, 1.0 + sys.floatinfo.epsilon / 2 > 1.0)