This Python program is designed to validate the content of a string. It checks if the string contains any alphanumeric, alphabetic, digit, lowercase, and uppercase characters. The user inputs a string, and the program returns five boolean values indicating the presence of each type of character.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution works by iterating over each character in the input string and checking if it meets any of the five conditions: is it alphanumeric, alphabetic, a digit, lowercase, or uppercase. It uses Python's built-in string methods to perform these checks. If a character meets a condition, the corresponding flag is set to True. The program then prints the status of each flag, which indicates whether the input string contained each type of character.
if __name__ == "__main__":
s = input()
flag_alnum = False
flag_alpha = False
flag_digit = False
flag_lower = False
flag_upper = False
for i in s:
if i.isalnum():
flag_alnum = True
if i.isalpha():
flag_alpha = True
if i.isdigit():
flag_digit = True
if i.islower():
flag_lower = True
if i.isupper():
flag_upper = True
print(flag_alnum)
print(flag_alpha)
print(flag_digit)
print(flag_lower)
print(flag_upper)
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.