0
def trafficlight(label):

    if label == "tl0":
        pass
    elif label == "tl1":
        print("STOP")

def person(label):

    if label == "pr0":
        pass
    elif label == "pr1":
        print("STOP")


label = "tl1"

if label == "tl0" or "tl1":
    trafficlight(label)

elif label == "pr0" or "pr1":
    person(label)

else:
    print("Keep Moving")

This is my code, there will be more elif but when I checked before continuing, I noticed that I cannot get any output if I write label other than "tl1". No STOP text for "pr1" or no other outputs for other things. Can you help me? Thanks in advance.

Btw, I wanted to create simple autonomous car's decision tree, if there is any easiest way, I'm open for help.

MKutlutas
  • 11
  • 4

1 Answers1

0

the error was with the or keyword. this code is working.

def trafficlight(label):

    if label == "tl0":
        pass
    elif label == "tl1":
        print("STOP")

def person(label):

    if label == "pr0":
        pass
    elif label == "pr1":
        print("STOP")


label = "tl1"

if label == "tl0" or label=="tl1":
    trafficlight(label)

elif label == "pr0" or label=="pr1":
    person(label)

else:
    print("Keep Moving")
Pratik Agrawal
  • 405
  • 3
  • 17