Answer to Question #327895 in Python for chinna

Question #327895

validation:


username should be in between 4 and 25

should start with letters but not underscore

should not be special characters


input:

google

output:

true


input:

google@123

output:

false


1
Expert's answer
2022-04-12T16:15:28-0400
import string 
def validate(name):
    if len(name) < 4 or len(name) > 25:
        return False
    
    if name[0] not in string.ascii_letters:
        return False


    for ch in name:
        if (ch not in string.ascii_letters and 
            ch not in string.digits and ch != '_'):
            return False
    return True


def main():
    name = input()
    if validate(name):
        print('true')
    else:
        print('false')


if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS