ATM PIN Code Validation
Write a function with the name validate atm.pin code that takes a word as an argument. ATM PIN is considered valid only if the given word contains Exactly 4 or 6 characters - All the characters should be digits.
Input
The input will be a single line containing a string.
Output
The output should be a single line containing either "Valid PIN Code or "Invalid PIN Code".
Explanation
For example, if the given word is "9837". the output should be "Valid PIN Code", as it contains exactly four characters and all the characters are digits.
Whereas, if the given word is "A289h4", the output should be "invalid PIN Code, though the given word contains exactly six characters, all the characters are not digits.
def is_valid_PIN(s):
if len(s) != 4 and len(s) != 6:
return False
for ch in s:
if ch not in '1234567890':
return False
return True
def main():
line = input()
if is_valid_PIN(line):
print('Valid PIN Code')
else:
print("Invalid PIN Code")
if __name__ == '__main__':
main()
Comments
Leave a comment