mercredi 21 octobre 2020

Python combining if statements [closed]

I want to filter all numbers, that have the length of 8 and start with an 1,8 or 9. It does filter the Invalid numbers, but not the Valid ones. Any ideas? Code:

num = input()

length = len(num)

digits = [d for d in num]
d1 = digits[0]


if int(d1) in set((1, 8, 9)) and length == '8':
    print("Valid")
else:
    print("Invalid")

Aucun commentaire:

Enregistrer un commentaire