From 1b00a694e2fe2ce11aa3d853a96a02a612ed0a5f Mon Sep 17 00:00:00 2001 From: KJK Date: Thu, 23 Dec 2021 10:45:11 +0000 Subject: [PATCH] Closes: #1 Updated validations.py python script. Fixed the behavior of validate_user function in validations.py. --- Course3/Lab4/validations.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Course3/Lab4/validations.py b/Course3/Lab4/validations.py index b18de65a2e..5e1ccb97a2 100644 --- a/Course3/Lab4/validations.py +++ b/Course3/Lab4/validations.py @@ -8,7 +8,8 @@ def validate_user(username, minlen): raise TypeError("username must be a string") if minlen < 1: raise ValueError("minlen must be at least 1") - + if not (('a' <= username[0] <= 'z') or ('A' <= username[0] <= 'Z')): + return False # Usernames can't be shorter than minlen if len(username) < minlen: return False @@ -19,6 +20,9 @@ def validate_user(username, minlen): if username[0].isnumeric(): return False return True - +print(validate_user("blue.kale", 3)) # True +print(validate_user(".blue.kale", 3)) # Currently True, should be False +print(validate_user("red_quinoa", 4)) # True +print(validate_user("_red_quinoa", 4)) # Currently True, should be False