mercredi 26 février 2020

Why are my python nested if statements not working? [duplicate]

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.

Aucun commentaire:

Enregistrer un commentaire