Created
July 1, 2020 08:46
-
-
Save JohnsonLuu/13f0036657196e53aab373c671263641 to your computer and use it in GitHub Desktop.
Strings Review - Code Academy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let’s start with username_generator. | |
Create a function called username_generator take two inputs, first_name and last_name and 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 Simpson the function should generate the username AbeSimp. | |
Now for the temporary password, they want the function to take the input user name and shift all of the letters by one to the right, so the last letter of the username ends up as the first letter and so forth. | |
For example, if the username is AbeSimp, then the temporary password generated should be pAbeSim. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def username_generator(first_name, last_name): | |
# no if statement needed even if first/last name are shorter than end bound of slicing | |
return first_name[:3] + last_name[:4] | |
''' | |
# solution without for loop | |
def password_generator(username): | |
return username[-1] + username[0:-1] | |
''' | |
def password_generator(username): | |
password = "" | |
for i in range(len(username)): | |
password = password + username[i - 1] | |
return password | |
# test cases | |
print(username_generator("J", "Le")) | |
print(password_generator("Jerry")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment