459,468 views
29 votes
29 votes
if person is male their username is the last 3 letters of their surname and the first 2 letters of their first name if a person is female their username is the first 3 letters of their first name and the last 2 letters of their last name. write an algorithm to output a username (Could you answer in Python pls)​

User Omnikron
by
2.5k points

1 Answer

25 votes
25 votes

gender = input("What's your gender? (`male` or `female`): ")

firstname = input("What's your firstname?: ")

surname = input("What's your surname?: ")

username = ""

if gender == "male":

username += surname[-3:]

username += firstname[0:2]

elif gender == "female":

username += firstname[0:3]

username += surname[-2:]

print(f'Your username is {username}')

User Hbot
by
3.0k points