from datetime import datetime as dt
class Employee:
def __init__(self, first, last, date_of_birth):
console.warn(f"__init__('{first}', '{last}', {date_of_birth})")
if not first:
raise ValueError('Missing first name')
if not last:
raise ValueError('Missing last name')
if not date_of_birth:
raise ValueError('Missing date of birth')
self.first = first
self.last = last
try:
self.date_of_birth = dt.strptime(date_of_birth, '%Y-%m-%d').date()
except:
raise ValueError(f"Invalid date of birth: '{date_of_birth}'")
def __str__(self):
console.warn('__str__()')
return f"Full Name: {self.first} {self.last}, Date of birth: {self.date_of_birth:%Y-%m-%d}"
@classmethod
def get(cls):
console.warn('get(cls)')
first = input(); print(f"First name: {first}")
last = input(); print(f"Last name: {last}")
date_of_birth = input() # yyyy-mm-dd
print(f"Date of birth: {date_of_birth}")
return cls(first, last, date_of_birth)
employee = Employee.get() # get class
print(employee)