Can you help with my code?

Why is this code not working?

def username_generator(first_name, last_name):
  for index in range(len(first_name)):
    for index2 in range(len(last_name)):
      if index > 2 and index2 > 3:
        username = first_name[:3] + last_name[:4]
        return username
      elif index <= 2:
        username = first_name + last_name[:4]
        return username

im getting

“Expected the name Mimiko Watanabe to produce the username MimWata, instead got MimikoWat”

Raw code is preferrable to an image. Are we to type your code in to test it? Please post the code in a reply.

Ok, I just edited it. Will keep in mind

1 Like

Not sure you need a nested list. There should be only two steps to arrive at a username.

first

will be first_name if its length is less than 4, else it will be the first three letters of the name.

last

will be last_name if its length is less than 5, else it will be the first four letters of that name.

1 Like

Yeah I guess me using a loop was the problem.

I redid it with this code and I finally solved it:

def username_generator(first_name, last_name):
  if len(first_name) > 3 and len(last_name) > 4:
    username = first_name[:3] + last_name[:4]
    return username
  if len(first_name) <= 3:
    username = first_name + last_name[:4]
    return username

And if the last name is short, with a long first name?

1 Like

Yeah I was going to add that but it accepted this. I’m not even sure why my first one didn’t even work or why this worked but it did.