This Python program is designed to validate user input UID. The validation is based on several conditions: the UID must contain at least two uppercase letters, at least three digits, must be exactly 10 alphanumeric characters, and no character should repeat.
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 using regular expressions to check if the input UID meets the required conditions. Four different regular expressions are used to check for uppercase letters, digits, alphanumeric characters and length, and repeating characters. The results of these checks are then used to determine if the UID is valid or not. If all conditions are met, the UID is considered valid, otherwise it is considered invalid.
import re
n = int(input())
upper_check = r".*([A-Z].*){2,}"
digit_check = r".*([0-9].*){3,}"
alphanumeric_and_length_check = r"([A-Za-z0-9]){10}$"
repeat_check = r".*(.).*\1"
for _ in range(n):
uid_string = input().strip()
upper_check_result = bool(re.match(upper_check, uid_string))
digit_check_result = bool(re.match(digit_check, uid_string))
alphanumeric_and_length_check_result = bool(
re.match(alphanumeric_and_length_check, uid_string)
)
repeat_check_result = bool(re.match(repeat_check, uid_string))
if (
upper_check_result
and digit_check_result
and alphanumeric_and_length_check_result
and not repeat_check_result
):
print("Valid")
else:
print("Invalid")
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.