Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Implemented by Pedro Izecksohn.")
- def isValidTrafficSequence (seq):
- if not seq:
- return True
- i=0
- while i<(len(seq)-1):
- i+=1
- if seq[i-1]=="red":
- if seq[i]=="green":
- continue
- return False
- if seq[i-1]=="yellow":
- if seq[i]=="red":
- continue
- return False
- if seq[i-1]=="green":
- if seq[i]=="yellow":
- continue
- return False
- print("Invalid data.")
- exit()
- return True
- def main():
- seq=[]
- s="a"
- while len(s):
- s=input()
- if len(s):
- seq.append(s)
- print(isValidTrafficSequence(seq))
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement