-1

I am making a logic gate program and have this code:

gate = input("Enter gate:\t")
in1 = input("\nEnter first input:\t")
in2 = input("\nEnter second input:\t")

if gate  == "OR":
  if in1 == 1:
    print("\nResult:\t1")

if gate  == "OR":
  if in1 == 1:
    print("\nResult:\t1")
  elif in2 == 1:
    print("\nResult:\t1")
  else:
    print("\nResult:\t0")

elif gate == "AND":
  if in1 == 1 and in2 == 1:
    print("\nResult:\t1")
  else:
    print("\nResult:\t0")

elif gate == "NAND":
  if in1 == 1 and in2 == 1:
    print("\nResult:\t0")
  else:
    print("\nResult:\t1")

elif gate == "XOR":
  if in1 != in2:
    print("\nResult:\t1")
  else:
    print("\nResult:\t0")

elif gate == "NOT":
  if in1 == 0:
    print("\nResult:\t1")
  else:
    print("\nResult:\t0")

elif gate == "NOR":
  if in1 == 0 and in2 == 0:
    print("\nResult:\t1")
  elif in1 == 0 and in2 == 1:
    print("\nResult:\t0")
  elif in1 == in2:
    print("\nResult:\t1")
  else:
    print("\nResult:\t0")

else:
  print("\nEnter a valid logic gate")

But it never returns anything.

I have also translated this into java and it also does not seem to be working

As an aside, on line 10, I get this error: [mccabe] Cyclomatic complexity too high: 16 (threshold 15)

What am I doing wrong?

Thanks in advance.

Malted_Wheaties
  • 132
  • 1
  • 10
  • 1
    `input` returns string, cast it to int `in1 = int(input("\nEnter first input:\t"))`. – Guy Feb 26 '20 at 13:49
  • 1
    You assume that numbers entered through `input` will be numbers, rather than strings looking like numbers. – L3viathan Feb 26 '20 at 13:49

1 Answers1

2

input() returns a string value, so in1 and in2 are strings, but your if statements are looking for ints. You need to change your 2. and 3. Line to :

gate = input("Enter gate:\t")
in1 = int(input("\nEnter first input:\t"))
in2 = int(input("\nEnter second input:\t"))
sxeros
  • 668
  • 6
  • 21