Dcoder icon

The light Switch @ Dcoder

By Lochard | As a newbie programmer | 16 Jul 2023


Problem: There is a light bulb on the stairs, which has two switches. The light turns on if and only if one of them is on(binary 1) and other is off(binary 0).You are given combinations of these switch find whether the bulb glow or not?

Input: Two bits a and b separated by space, each representing a switch position,(0=off , 1=on)

Output: Print 1 if bulb will turn on else print 0.

Constraints: a=b=0/1

Sample Input: 1 1

Sample Output: 

0

a, b = map(int, input().split())
print(a^b)

How do you rate this article?

2


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.