Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. Descriptions 100/100 with regex
- # https://judge.softuni.org/Contests/Practice/Index/1140?fbclid=IwAR0szSoRJQozKH6o_5Bwi1U9Y-5R6OcPT_l6jSJX73WzJq_BmmhONJbVkEc#2
- import re
- data = input()
- pattern_names = r'(name is\s)([A-Z][a-z]+)+\s?([A-Z][a-z]+)'
- pattern_years = r'((\d+)\s(years))'
- pattern_b_day_data = r'(\d{2}-\d{2}-\d{4}).?'
- valid_data = []
- db_empty = False
- printed_once = False
- while not data == 'make migrations':
- matched_names = re.findall(pattern_names, data)
- if matched_names:
- first_name = matched_names[0][1]
- last_name = matched_names[0][2]
- valid_data.append(first_name + " " + last_name)
- else:
- data = input()
- db_empty = True
- continue
- matched_years = re.findall(pattern_years, data)
- if matched_years:
- years_old = int(matched_years[0][1])
- if 9 < years_old <= 99:
- valid_data.append(years_old)
- else:
- matched_years = []
- db_empty = True
- matched_b_day_data = re.findall(pattern_b_day_data, data)
- if matched_b_day_data:
- b_day_data = ''.join(matched_b_day_data)
- else:
- data = input()
- db_empty = True
- continue
- valid_data.append(b_day_data)
- if matched_names and matched_years and matched_b_day_data:
- print(f'Name of the person: {valid_data[0]}.')
- print(f'Age of the person: {valid_data[1]}.')
- print(f'Birthdate of the person: {valid_data[2]}.')
- valid_data.clear()
- printed_once = True
- db_empty = True
- data = input()
- if db_empty and not printed_once:
- print('DB is empty')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement