Created
April 24, 2019 15:02
-
-
Save theArjun/ee4b554df327ee01348fd2b999b6652f to your computer and use it in GitHub Desktop.
Validating UID - Hackerrank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://www.hackerrank.com/challenges/validating-uid/problem | |
| def uid_validator(uid): | |
| characters = list(uid) | |
| if len(uid) != 10: | |
| # print("Length property missed.") | |
| return False | |
| # Checks alphanumeric property | |
| try: | |
| first_char = int(characters[0]) | |
| except ValueError: | |
| pass | |
| else: | |
| # print("Alphanumeric Property missed.") | |
| return False | |
| # Miniumum digits and uppercase letter property | |
| digit_count = 0 | |
| uppercase_count = 0 | |
| for char in characters: | |
| try: | |
| if characters.count(char) > 1: | |
| # print("Repeated Character found.") | |
| return False | |
| if int(char) in range(10): | |
| digit_count += 1 | |
| except ValueError: | |
| if char.isupper(): | |
| uppercase_count += 1 | |
| continue | |
| if digit_count < 3 and uppercase_count < 3: | |
| # print("Minimum Digit or Uppercase property missed.") | |
| return False | |
| return True | |
| if __name__ == "__main__": | |
| input_no = int(input()) | |
| for i in range(input_no): | |
| uid = input() | |
| if uid_validator(uid): | |
| print("Valid") | |
| else: | |
| print("Invalid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment