We only want to perform slices on inputs where the first name has at least 3 characters, and the last name has at least 4 characters. If either of the the inputs do not meet these requirements, we will not be performing any slicing. So, we want to check if the length of our inputs meet the slicing requirements:
if len(first_name) < 3 or len(last_name) < 4:
username = first_name + last_name
If the length of first_name OR the length of last_name do not meet the slicing requirements, we can skip slicing and simply concatenate the two inputs. For example, if we were to input (“Ty”, “Jordan”) or (“Adam”, “Lee”) or (“Wu”, “Yan”) the function would detect that one or both of the inputs do not meet the slicing requirements. The function would then return “TyJordan”, “AdamLee”, or “WuYan”.
Now, if first_name and last_name meet the length requirements, we can move on to the slicing operations. For those, we concatenate the first 3 letters of the first name with the first 4 letters of the last name:
username = first_name[:3] + last_name[:4]
In this second half of the function, the input data has already passed the length check, so we know that we can perform the slicing work. We can use first_name[:3] to get the first 3 letters of the first name, and last_name[:4] to get the first 4 letters of the last name.
For instance: “Adam”[:3] would be “Ada” and “Jameson”[:4] would be “Jame”, we then concatenate those into “AdaJame” and return the result.