Thursday , September 19 2024

What is the output of the following snippet? a = 1 b = 0 c = a & b d = a | b e = a ^ b print(c + d + e)

Questions BankCategory: Python Essentials 1What is the output of the following snippet? a = 1 b = 0 c = a & b d = a | b e = a ^ b print(c + d + e)
What is the output of the following snippet?

a = 1
b = 0
c = a & b
d = a | b
e = a ^ b
 
print(c + d + e)
  • 0
  • 1
  • 3
  • 2

Explanation: Let’s analyze this example:

  • the a variable is assigned the integer value of 1,
  • the b variable is assigned the integer value of 0,
  • the c variable is assigned the and bitwise result of a & b, which is 0,/li>
  • the d variable is assigned the or bitwise result of a | b, which is 1,
  • the e variable is assigned the xor bitwise result of a ^ b, which is 1,
  • the sum of the c,d and e variables is printed on the console, which is 2.

More Questions: Python Essentials 1 – Module 3 Test