hacker rank python(String Validator)

STRING VALIDATOR


if __name__ == '__main__':
    s = input()
    print(len([True for c in s if c.isalnum()]) != 0)
    print(len([True for c in s if c.isalpha()]) != 0)
    print(len([True for c in s if c.isdigit()]) != 0)
    print(len([True for c in s if c.islower()]) != 0)
    print(len([True for c in s if c.isupper()]) != 0)

Compiler Message
Success
Input (stdin)Download
qA2
Expected OutputDownload
True
True
True
True
True

Comments

Unknown said…
Else condition is not exist here so,how can we pass all test cases in which else condition is exist.
Unknown said…
# i think you'er talking about this.But the code given above is more efficient
if __name__ == '__main__':
s = input()
alphanumeric=0
alphabetical=0
digits=0
lowercase=0
uppercase=0
for i in range(len(s)):
if(s[i].isalnum()):
alphanumeric+=1
if(s[i].isalpha()):
alphabetical+=1
if(s[i].isdigit()):
digits+=1
if(s[i].islower()):
lowercase+=1
if(s[i].isupper()):
uppercase+=1
if(alphanumeric>0):
print(True)
else:
print(False)
if(alphabetical>0):
print(True)
else:
print(False)
if(digits>0):
print(True)
else:
print(False)
if(lowercase>0):
print(True)
else:
print(False)
if(uppercase>0):
print(True)
else:
print(False)

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions