We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if name == 'main':
s = input()
is_alpha = False
is_alnum = False
is_digit = False
is_lower = False
is_upper = False
for c in s:
if c.isalpha():
is_alpha = True
if c.isalnum():
is_alnum = True
if c.isdigit():
is_digit = True
if c.islower():
is_lower = True
if c.isupper():
is_upper = True
Solution 2: with any
if __name__ == '__main__':
s = input()
print(any(c.isalnum() for c in s))
print(any(c.isalpha() for c in s))
print(any(c.isdigit() for c in s))
print(any(c.islower() for c in s))
print(any(c.isupper() for c in s))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
String Validators
You are viewing a single comment's thread. Return to all comments →
solution 1: without using any function
if name == 'main': s = input() is_alpha = False is_alnum = False is_digit = False is_lower = False is_upper = False
for c in s: if c.isalpha(): is_alpha = True if c.isalnum(): is_alnum = True if c.isdigit(): is_digit = True if c.islower(): is_lower = True if c.isupper(): is_upper = True
print(is_alnum) print(is_alpha) print(is_digit) print(is_lower) print(is_upper)