Technology

Programming

Post Page Advertisement [Top]

competitive programmingHaker Rank SolutionsPython

Validating UID - Hacker rank python code solution

ABCXYZ company has up to  employees.
The company decides to create a unique identification number (UID) for each of its employees.
The company has assigned you the task of validating all the randomly generated UIDs.
A valid UID must follow the rules below:
  • It must contain at least  uppercase English alphabet characters.
  • It must contain at least  digits ( - ).
  • It should only contain alphanumeric characters ( -  -  &  - ).
  • No character should repeat.
  • There must be exactly  characters in a valid UID.
Input Format
The first line contains an integer , the number of test cases.
The next  lines contains an employee's UID.
Output Format
For each test case, print 'Valid' if the UID is valid. Otherwise, print 'Invalid', on separate lines. Do not print the quotation marks.
Sample Input
2
B1CD102354
B1CDEF2354
Sample Output
Invalid
Valid
Explanation
B1CD102354 is repeating → Invalid
B1CDEF2354: Valid


# Enter your code here. Read input from STDIN. Print output to STDOUT
def UpperCaseCount(UID):
    count = 0    for letter in UID:
        if 'A' <= letter <= 'Z':
            count += 1    return count
def DigitCount(UID):
    count = 0    for letter in UID:
        if '0' <= letter <= '9':
            count += 1    return count

def AnyCharRepeated(UID):
    for char in UID:
        if UID.count(char) >1:
            return True    return False
for i in range(int(input())):
    UID = input()
    if len(UID) != 10:
        print("Invalid")
    elif UID.isalnum() == False:
        print("Invalid")
    elif UpperCaseCount(UID) < 2:
        print("Invalid")
    elif DigitCount(UID) < 3:
        print("Invalid")
    elif AnyCharRepeated(UID) == True:
        print("Invalid")
    else:
        print("Valid")

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib