ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(10 // 3 * 3 + 10 % 3 == 10, -10 // 3 * 3 + -10 % 3 == -10, 10 // -3 * -3 + 10 % -3 == 10)
- A. True False True
- B. False True True
- C. True True False
- D. True True True
Correct answer: D. True True True
Floor division and modulo satisfy a == (a // b) * b + a % b for every nonzero b, so all three checks are True.
More Python Programming questions
- What is printed? python print(0 == False, '' == False, [] == False, None == False)
- What is printed? python from collections import Counter print(Counter('hello').mostcommon(2))
- What is printed? python def keyfn(p): return (-p[1], p[0]) people = [('bo', 3), ('al', 5), ('cy', 3)] print([p[0] for p in sorted(people…
- What is printed? python s = 'abcabc' print(s.find('c'), s.find('c', 3), s.rfind('c', 0, 4), s.count('c', 2))
- What is printed? python nums = [1, 2, 3, 4, 5] print([nums[i] for i in range(len(nums) - 1, -1, -2)], nums[::-2][0])
- What is printed? python def walk(s): total = 0 for i, ch in enumerate(s, start=1): if ch.isupper(): total += i else: total -= i return…