Python - is digit
isdigit()
Question
ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits.
If the function is passed a valid PIN string, return true, else return false.
Best answer
len(pin)
in (4, 6) is good thing to knowisdigit()
function is to check it contains only number (>0)
def validate_pin(pin):
return len(pin) in (4, 6) and pin.isdigit()
My Dumn Try
def validate_pin(pin):
#return true or false
if pin.isdigit() == False:
return False
elif int(pin) < 0:
return False
elif len(pin) == 4:
return True
elif len(pin) == 6:
return True
else:
return False