'check if a pin is long 4 or 6 digits or not [closed]
I just started learning py and i tried to create a simple program that checks whether a pin is long a 4 or 6 digits or not, but somehow it doesn't work.
def validate_pin(pin):
if len(pin) == 4 or len(pin) == 6:
return true
else:
return false
Solution 1:[1]
The value passed to validate_pin() would need to be of type str for this to make sense. Consider a PIN number of 0001. That's a valid PIN number but when expressed as int it isn't. Therefore:
def validate_pin(pin):
return len(pin) == 4 or len(pin) == 6
Solution 2:[2]
Python booleans are capitalized, so you have to change true to True and false to False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Albert Winestein |
| Solution 2 | Gabriel Lobo |
