ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(~5 == -6, ~(-5) == 4, (-5) >> 1 == -2, -5 // 2 == -3)
- A. True False False True
- B. True True False True
- C. True True True True
- D. False True False True
Correct answer: B. True True False True
~x equals -x - 1, so ~5 is -6 and ~(-5) is 4. Right shift on a negative number rounds toward negative infinity, so -5 >> 1 is -3, not -2. Floor division also gives -3.
More Python Programming questions
- What is printed? python import unicodedata print(unicodedata.normalize('NFC', 'eu0301') == 'é', len(unicodedata.normalize('NFD', 'é'))…
- What is printed? python print('a1'.isalnum(), '١'.isalnum(), ' '.isspace(), ''.isspace(), 'u00a0'.isspace())
- What is printed? python def fermatinverse(a, p): return pow(a, p - 2, p) print(fermatinverse(3, 7) == pow(3, -1, 7), 3 fermatinverse(3, 7)…
- What is printed? python print(sorted(['beta', 'Alpha', 'alpha', 'Beta'], key=str.lower))
- What is printed? python x = 0.1 + 0.7 print(x, x 10, int(x 10), round(x 10))
- What is printed? python print(int('3' 3) + int('4' 2) 2, '3' 3 + '4' 2 2)