ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(1 < 2 < 3 == 3.0 != 4, 1 < 2 > 3, (1 < 2) > 3, 'a' < 'b' < 'a')
- A. True True False False
- B. True False True False
- C. True False False True
- D. True False False False
Correct answer: D. True False False False
Comparisons chain, so 1 < 2 < 3 == 3.0 != 4 is True only when every adjacent pair holds. 1 < 2 > 3 needs 2 > 3, which fails, while (1 < 2) > 3 compares True with 3. 'a' < 'b' < 'a' fails at the last step.
More Python Programming questions
- What is printed? python x = 0b1011 print(x & ~(1 << 1), x ^ (1 << 2), x | (1 << 4), (x >> 1) & 1)
- What is printed? python words = ['bb', 'a', 'ccc', 'aa'] print(sorted(words, key=lambda w: (-len(w), w)))
- What is printed? python pairs = [(1, 'b'), (1, 'a'), (0, 'c')] print(sorted(pairs, key=lambda p: p[0]), sorted(pairs))
- What is printed? python print(int('0b11', 0) + int('0o11', 0) + int('0x11', 0), int('11', 16), int('-0b11', 0))
- What is printed? python from math import inf print(inf - 1 == inf, 2 inf, -inf < -10 400, inf > 10 400)
- What is printed? python print(sum(1 for c in 'a1 b2' if c.isalpha()), sum(1 for c in 'a1 b2' if c.isdigit()), sum(c.isspace() for c in 'a1…