Advertisement
GeorgiLukanov87

03. Descriptions Python Fundamentals Exam - 26 August 2018 100/100

Jul 19th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. # 03. Descriptions Python Fundamentals Exam - 26 August 2018 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/1140#2
  3.  
  4. import re
  5.  
  6. data = input()
  7.  
  8. pattern_names = r'(name is\s)([A-Z][a-z]+)+\s?([A-Z][a-z]+)'
  9. pattern_years = r'((\d+)\s(years))'
  10. pattern_b_day_data = r'(\d{2}-\d{2}-\d{4}).?'
  11. valid_data = []
  12. db_empty = False
  13. printed_once = False
  14. while not data == 'make migrations':
  15.     matched_names = re.findall(pattern_names, data)
  16.     if matched_names:
  17.         first_name = matched_names[0][1]
  18.         last_name = matched_names[0][2]
  19.         valid_data.append(first_name + " " + last_name)
  20.     else:
  21.         data = input()
  22.         db_empty = True
  23.         continue
  24.  
  25.     matched_years = re.findall(pattern_years, data)
  26.     if matched_years:
  27.         years_old = int(matched_years[0][1])
  28.         if 9 < years_old <= 99:
  29.             valid_data.append(years_old)
  30.         else:
  31.             matched_years = []
  32.             db_empty = True
  33.  
  34.     matched_b_day_data = re.findall(pattern_b_day_data, data)
  35.     if matched_b_day_data:
  36.         b_day_data = ''.join(matched_b_day_data)
  37.     else:
  38.         data = input()
  39.         db_empty = True
  40.         continue
  41.  
  42.     valid_data.append(b_day_data)
  43.     if matched_names and matched_years and matched_b_day_data:
  44.         print(f'Name of the person: {valid_data[0]}.')
  45.         print(f'Age of the person: {valid_data[1]}.')
  46.         print(f'Birthdate of the person: {valid_data[2]}.')
  47.         valid_data.clear()
  48.         printed_once = True
  49.         db_empty = True
  50.  
  51.     data = input()
  52.  
  53. if db_empty and not printed_once:
  54.     print('DB is empty')
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement