mercredi 27 mai 2020

If-else condition with null block

I have an input that looks like below. I have to write an if a condition that if first and second value both present then print(some value) and if only first value present then print(first)

My Input:

['10']
['0', '000']
['0', '000']
['10']
['10']
['10']

My code:

a = value[0]
b = value[1]

if a and b is not None:
    print("both value"
elif b is None:
    print("first)
else:
    return ""

Error:
List out of index error I am getting because value[1] is not present in first line.
How can I solve this?

Aucun commentaire:

Enregistrer un commentaire