Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple DataClass solution in Clear category for Every Person is Unique by swagg010164
from datetime import datetime
from dataclasses import dataclass
@dataclass
class Person:
first_name: str
last_name: str
birth_date: None
job: str
working_years: int
salary: int
country: str
city: str
gender: str = 'unknown'
work_repr = {"male": 'He is a ', "female": 'She is a ', "unknown": 'Is a '}
def __post_init__(self):
self.birth_date = datetime.strptime(self.birth_date, '%d.%m.%Y')
def name(self):
return f'{self.first_name} {self.last_name}'
def age(self):
return 2018 - self.birth_date.year - ((1, 1) < (self.birth_date.month, self.birth_date.day))
def work(self):
return self.work_repr[self.gender] + self.job
def money(self):
return "{:,}".format(self.working_years * self.salary * 12).replace(',', ' ')
def home(self):
return f"Lives in {self.city}, {self.country}"
Nov. 9, 2019
Comments: