0
def question2_a(num_str):  # 1001
    if len(num_str) == 0:
        return True
    if num_str[0] != ("0" or "1"):
        return False
    return question2_a(num_str[1: ])

print(question2_a("100"))

I cant understand, why do I get False?? the numbers are "0" or "1", but I still get False...

same with this code:

def question2_a(num_str):  # 1001
    if len(num_str) == 0:
         return True
    if num_str[0] == ("1" or "0"):
         return question2_a(num_str[1: ])

 print(question2_a("1001010"))

Why do I get None here? it is really annoying, I am doing nothing wrong, but I keep getting None here although there is no problem

And lastly:

def question2_a(num_str):  # 1001
    if len(num_str) == 0:
        return True
     if num_str[0] == ("1" or "0"):
        return question2_a(num_str[1: ])
    else:
         return False

 print(question2_a("1001010"))

Why do I get False here also? I should get True..

0 Answers0