the comments in the code should explain everything, brainly's formatting might be weird
gate = raw_input("Enter logic gate :").upper()#.upper() so lower/upper case of input doesn't matter 
firstInput = raw_input("Enter first input :")#raw_input() for python 2.7, input() for 3
secondInput = raw_input("Enter second input :")
if (firstInput!="0" and firstInput!="1") or (secondInput!="0" and secondInput!="1"):
 print("inputs must be 0 or 1")#ensure all inputs are in boolean range
 quit()
firstInput=firstInput=="1"#convert "1" to true and "0" to false
secondInput=secondInput=="1"
if gate=="AND" or gate=="NAND":
 result=firstInput and  secondInput
elif gate=="OR" or gate=="NOR":
 result=firstInput or secondInput
elif gate=="XOR":
 result=firstInput!=secondInput
else:#handle case of unknown/mistyped gates
 print(gate+" is not known")
 quit()
if gate=="NOR" or gate=="NAND":
 result=not result#invert result for nor and nand
print("Result = "+str(int(result)))#uses int so 1/0 are printed instead of True/False