Answer to Question #318501 in Python for sainath

Question #318501

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.


1
Expert's answer
2022-03-26T05:45:40-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS