Link to lesson
May I please get a reply on why my code is not accepted by Codecademy?
Copeland’s Corporate Company has finalized what they want their username and temporary password creation to be and have enlisted your help, once again, to build the function to generate them. In this exercise, you will create two functions,
Let’s start with
username_generator. Create a function called
username_generatortake two inputs,
last_nameand returns a
username. The username should be a slice of the first three letters of their first name and the first four letters of their last name. If their first name is less than three letters or their last name is less than four letters it should use their entire names.
For example, if the employee’s name is
Abe Simpsonthe function should generate the username
def username_generator(first_name, last_name): if len(first_name) <= 3 and len(last_name) >= 4: username = first_name + last_name[:4] if len(first_name) > 3 and len(last_name) < 4: username = first_name[:3] + last_name if len(first_name) > 3 and len(last_name) > 4: username = first_name[:3] + last_name[:4] return username print(username_generator('Abe', 'Simpson'))
It works in the compiler, I get the AbeSimp, but I get the error from Codecademy which says - “Incorrect: local variable ‘username’ referenced before assignment”
Thank you for any assistance you may provide!