Hi I could use some pointers with my code at the bottom of this post. (I started learning Python Recently btw, so any feedback even if it doesn't relate entirely to the question is much appreciated)
So Basically my code needs to do/factor in the following:
- Print out someone's userID based on their first and last name.
- The userid cannot be > 8 characters total
- The first 2 characters of the first name are to be used followed by the last 6 of the surname.
Everything works as I want it to for names such as:
John Doe = "jodoe"
Marie Anne Richardson = "maardson"
But it all changes when we look at examples such as:
J.K.Rowling = "j.owling"
John D O E = "jod o e "
I don't want to allow the usage of punctuation and integers and I am unable to control whitespace in between characters. In some contexts first names will be something like "Marie Anne" or people may have multiple last names, so whitespace in between should definitely be allowed as user input but what I'm looking for is to have it stripped.
So the user can type "Marie Anne Richardson" and this will still allow user "maardson". However:
"John D O E" would result in "jodoe". "John Doe Doe" would result in "jodoedoe"
Code:
print(
"Welcome to the UserID Tool, a few questions will be asked to generate your Unique UserID"
)
prompt = ">"
first_name = input(f"What is your First Name?\n{prompt}").lower().strip()
last_name = input(f"What is your Last Name\n{prompt}").lower().strip()
len_first_name = len(first_name)
len_last_name = len(last_name)
max_userid_len = 8
if len_first_name + len_last_name > max_userid_len:
new_last_name = last_name[-6:].strip()
print(f"Your user id is {first_name[0:2]}{new_last_name}")
else:
print(f"Your user id is {first_name[0:2]}{last_name}")