Great work! I hope you are now starting to see the potential of strings and how they can be used to solve a huge variety of problems.
In this lesson you learned:
string_name[index]. These indices start at 0.
len()can be used to determine the number of characters in a string.
Let’s put your new skills to the test!
Copeland’s Corporate Company has finalized what they want to 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_generator take two inputs,
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
Great work! 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
Start by defining the function
password_generator so that it takes one input,
username and in it define an empty string named
password_generator create a for loop that iterates through the indices username by going from
To shift the letters right, at each letter the for loop should add the previous letter to the string