Advertisement
Alien_420_py

Untitled

Feb 23rd, 2021
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. def main():
  2.     with open("registrations.txt", 'r', encoding="utf-8") as file:
  3.         try:
  4.             a = open("registrations_good.log", "w")
  5.             v = open('registrations_bad.log', 'w')
  6.             for line in file:
  7.                 try:
  8.                     operand_1, operation, operand_2 = line.split(' ')
  9.                 except ValueError:
  10.                     continue
  11.                 try:
  12.                     match = re.search('\d+', operand_1)
  13.                     matchtwo = re.search('\W+', operation)
  14.                     if match is None:
  15.                         name = True
  16.                     else:
  17.                         name = False
  18.                         raise NameError
  19.                         continue
  20.                     if matchtwo is not None:
  21.                         mail = True
  22.                     else:
  23.                         mail = False
  24.                         raise ValueError
  25.                         continue
  26.                     if 10 < int(operand_2[:-1]) < 100:
  27.                         age = True
  28.                     else:
  29.                         age = False
  30.                         raise ValueError
  31.                     if name and mail and age:
  32.                         open("registrations_good.log", "a")
  33.                         a.write(operand_1, operand_2, operation + "\n")
  34.                     else:
  35.                         open("registrations_bad.log", "a")
  36.                         v.write(operand_1, operand_2, operation)
  37.  
  38.                 except NameError:
  39.                     print('nameerror')
  40.                     continue
  41.                 except ValueError:
  42.                     print("Value")
  43.                     continue
  44.                 except TypeError:
  45.                     print("type")
  46.         except ValueError:
  47.             print('Value 2')
  48.  
  49.  
  50. main()
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement