Why can't I print?

In the second part, how could I print the result? I try to print (password_generator (username)), but I got a name error

def password_generator (username):
password =
for i in range (0,len(username)):
password += username [i-1]
return password

First, it looks like you setup password as an empty list, not an empty string. Otherwise our functions look the same.

Assuming you wrote a username outside of the function (ex: username = ‘DonTrum’) and called the function (ex: print(password_generator(username)), you should get the result (ex: ‘mDonTru’). Of course this is sort of cheating because it ignores the first function entirely.

I also get a name error if I try to call the first function (which works) and then the second one. To make them work together I don’t write a username outside of the function, and make the first function the input of the second one. i.e print(password_generator(username_generator(first_name, last_name)))

There is probably a better way to go about this, but that is what worked for me.

1 Like