In this HackerRank String Validators problem you are given a string. your task is to find out if the string contains: alphanumeric characters, alphabetical characters, digits, lowercase and uppercase characters.

HackerRank String Validators in python problem solution

HackerRank String Validators in python problem solution

s = input()

for i in range(0, len(s)):
    if s[i].isalnum():
        print('True')
        break
    if i == len(s) - 1:
        print('False')

for i in range(0, len(s)):
    if s[i].isalpha():
        print('True')
        break
    if i == len(s) - 1:
        print('False')
        
for i in range(0, len(s)):
    if s[i].isdigit():
        print('True')
        break
    if i == len(s) - 1:
        print('False')
        
for i in range(0, len(s)):
    if s[i].islower():
        print('True')
        break
    if i == len(s) - 1:
        print('False')
        
for i in range(0, len(s)):
    if s[i].isupper():
        print('True')
        break
    if i == len(s) - 1:
        print('False')

Second solution

s = list(input())
flag1 = False
flag2 = False
flag3 = False
flag4 = False
flag5 = False
for i in range(len(s)):
    if s[i].isalnum() == True:
        flag1 = True
    if s[i].isalpha() == True:
        flag2 = True
    if s[i].isdigit() == True:
        flag3 = True
    if s[i].islower() == True:
        flag4 = True
    if s[i].isupper() == True:
        flag5 = True
else:
    print (flag1)
    print (flag2)
    print (flag3)
    print (flag4)
    print (flag5)