Level 1: Beginner
#VALID USERNAME
def is_valid_username(username):
return (5 <= len(username) <= 15 and username[0].isalpha() and username.isalnum())
while True:
print('5 to 15 characteres and must start with a letter')
prompt = input('Type your username here (or type "exit" to quit): ')
if prompt.lower() == "exit":
print("Exiting...")
break
if is_valid_username(prompt):
print('Valid username')
else:
print('Username invalid. Please try again.')
username = input('Write here your name: ')
def check_username_validity(username):
characters = len(username)
key_num = username.isalnum()
key_alpha = username[0].isalpha()
if (characters > 15) or (characters < 5):
print('Your username is invalid because it doesnt have the exact numbers right!')
elif key_num is not True:
print('Your username does not contain only alphanumerics.')
elif key_alpha is not True:
print('The first character of the username must be a letter.')
check_username_validity(username)
def check_username_validity(usr_name):
if len(usr_name)>=5 and len(usr_name)<=15:
if usr_name[0].isalpha():
for ch in usr_name:
if ch.isalnum():
pass
return "Invalid Username - Only letters and numbers are allowed"
return "Valid username"
return "Invalid Username - First letter in username is should be character"
return "Invalid - Insufficient user name length/characters"
if __name__ == "__main__":
usr_name = input("Enter Username - contain chars/digits - min length [5] to max length [15] chars:")
print(check_username_validity(usr_name))
The hint and show code redirects do not work for me. I have cleared cookies, changed devices and ip's. I also went to the acactual substack page as opposed to the email.
Hi Shalako, sorry about that. Please check the links again. They should work now.
Perfect! Thanks for the quick response.
#VALID USERNAME
def is_valid_username(username):
return (5 <= len(username) <= 15 and username[0].isalpha() and username.isalnum())
while True:
print('5 to 15 characteres and must start with a letter')
prompt = input('Type your username here (or type "exit" to quit): ')
if prompt.lower() == "exit":
print("Exiting...")
break
if is_valid_username(prompt):
print('Valid username')
break
else:
print('Username invalid. Please try again.')
username = input('Write here your name: ')
def check_username_validity(username):
characters = len(username)
key_num = username.isalnum()
key_alpha = username[0].isalpha()
if (characters > 15) or (characters < 5):
print('Your username is invalid because it doesnt have the exact numbers right!')
elif key_num is not True:
print('Your username does not contain only alphanumerics.')
elif key_alpha is not True:
print('The first character of the username must be a letter.')
else:
print('Valid username')
check_username_validity(username)
def check_username_validity(usr_name):
if len(usr_name)>=5 and len(usr_name)<=15:
if usr_name[0].isalpha():
for ch in usr_name:
if ch.isalnum():
pass
else:
return "Invalid Username - Only letters and numbers are allowed"
return "Valid username"
else:
return "Invalid Username - First letter in username is should be character"
else:
return "Invalid - Insufficient user name length/characters"
if __name__ == "__main__":
usr_name = input("Enter Username - contain chars/digits - min length [5] to max length [15] chars:")
print(check_username_validity(usr_name))
The hint and show code redirects do not work for me. I have cleared cookies, changed devices and ip's. I also went to the acactual substack page as opposed to the email.
Hi Shalako, sorry about that. Please check the links again. They should work now.
Perfect! Thanks for the quick response.