Advertisement
SimeonTs

SUPyF2 Text-Pr.-Ex. - 01. Valid Usernames

Oct 27th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. """
  2. Text Processing - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1740#0
  4.  
  5. SUPyF2 Text-Pr.-Ex. - 01. Valid Usernames
  6.  
  7. Problem:
  8. Write a program that reads user names on a single line (joined by ", ") and prints all valid usernames.
  9. A valid username is:
  10. • Has length between 3 and 16 characters
  11. • Contains only letters, numbers, hyphens and underscores
  12. • Has no redundant symbols before, after or in between
  13.  
  14. Examples:
  15. -----------------------------------------------------------------------------
  16.  
  17. Input:                                                          Output:
  18. sh, too_long_username, !lleg@l ch@rs, jeffbutt                  jeffbutt
  19. -----------------------------------------------------------------------------
  20. Input:                                                          Output:
  21. Jeff, john45, ab, cd, peter-ivanov, @smith                      Jeff
  22.                                                                John45
  23.                                                                peter-ivanov
  24. -----------------------------------------------------------------------------
  25. """
  26. all_names = input().split(", ")
  27. valid_names = []
  28. for name in all_names:
  29.     if 3 <= len(name) <= 16:
  30.         all_valid = True
  31.         valid_name = ""
  32.         for letter in name:
  33.             if letter.isalpha() or letter.isdigit() or letter == "-" or letter == "_":
  34.                 valid_name += letter
  35.             else:
  36.                 all_valid = False
  37.         if all_valid:
  38.             valid_names += [valid_name]
  39. print("\n".join(valid_names))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement