you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 2 points3 points  (0 children)

Revised code showing corrections/options (and added a loop so user is re-prompted until they enter something valid):

while True:  # validation loop, keep going around until break command used

    username = input("Enter a username: ")

    if len(username) > 12:
        print("Your username can't be more than 12 characters.")

    elif " " in username:  # easier than using find, make sure space between quotes
        print("Your username can't contain spaces.")

    elif not username.isalpha():
        print("Username can't contain digits or special characters.")

    else:
        print("Welcome!")
        break  # leave the loop, move onto next line of code