Advertisement
ALEXANDAR_GEORGIEV

Exerceses_Error_Handlink

May 26th, 2023
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. # Exerceses Error Handlink
  2. # email_validator_HOMEWORK
  3. from re import findall
  4.  
  5.  
  6. class NameTooShortError(Exception):
  7.     pass
  8.  
  9.  
  10. class MustContainAtSymbolError(Exception):
  11.     pass
  12.  
  13.  
  14. class InvalidDomainError(Exception):
  15.     pass
  16.  
  17.  
  18. class MoreThanOneAtSymbolError(Exception):
  19.     pass
  20.  
  21.  
  22. class InvalidNameError(Exception):
  23.     pass
  24.  
  25.  
  26. MIN_LENGTH = 4
  27.  
  28. VALID_DOMAINS = (".com", ".bg", ".net", ".org")
  29.  
  30. pattern_name = r'\w+'
  31. pattern_domain = r'\.[a-z]+'
  32.  
  33. email = input()
  34.  
  35. while email != "End":
  36.  
  37.     if email.count("@") > 1:
  38.         raise MoreThanOneAtSymbolError("Email should contain only one @ symbol!")
  39.  
  40.     if len(email.split("@")[0]) < MIN_LENGTH:
  41.         raise NameTooShortError("Name must be more than 4 characters!")
  42.  
  43.     if "@" not in email:
  44.         raise MustContainAtSymbolError("Email must contain @!")
  45.  
  46.     if findall(pattern_name, email)[0] != email.split("@")[0]:
  47.         raise InvalidNameError("Name can contain only letters, digits and underscores!")
  48.  
  49.     if findall(pattern_domain, email)[-1] not in VALID_DOMAINS:
  50.         raise InvalidDomainError("Domain must be one of the following: .com, .bg, .org, .net")
  51.  
  52.     print("Email is valid")
  53.  
  54.     email = input()
  55.  
  56.  
  57. # Numbers_dictionary_ Homework
  58. numbers_dictionary = {}
  59.  
  60. line = input()
  61. while line != "Search":
  62.     numbers_as_string = line
  63.  
  64.     try:
  65.         number = int(input())
  66.         numbers_dictionary[numbers_as_string] = number
  67.     except ValueError:
  68.         print(f"The variable number must be an integer")
  69.     line = input()
  70.  
  71.  
  72. line = input()
  73. while line != "Remove":
  74.     searched = line
  75.     try:
  76.         print((numbers_dictionary[searched]))
  77.     except KeyError:
  78.         print(f"Number does not exist in dictionary")
  79.     line = input()
  80.  
  81. line = input()
  82. while line != "End":
  83.     searched = line
  84.     try:
  85.         del numbers_dictionary[searched]
  86.     except KeyError:
  87.         print(f"Number does not exist in dictionary")
  88.     line = input()
  89.  
  90. print(numbers_dictionary)
  91.  
  92.  
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement