Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Every Person is Unique by tom-tom
from datetime import date, datetime
class Person:
CURRENT_DATE = date(2018, 1, 1)
def __init__(self, first_name, last_name, birth_date, job, working_years, salary, country, city, gender='unknown'):
self._first_name = first_name
self._last_name = last_name
self._birth_date = datetime.strptime(birth_date, '%d.%m.%Y').date()
self._job = job
self._working_years = working_years
self._salary = salary
self._country = country
self._city = city
self._gender = gender
def name(self):
return f'{self._first_name} {self._last_name}'
def age(self, at_date=CURRENT_DATE):
return at_date.year - self._birth_date.year - (
1 if at_date.month < self._birth_date.month or
at_date.month == self._birth_date.month and at_date.day < self._birth_date.day else 0)
def work(self):
return {'male': 'He is', 'female': 'She is', 'unknown': 'Is'}[self._gender] + ' a ' + self._job
def money(self):
return '{:,}'.format(round(self._working_years * 12 * self._salary)).replace(',', ' ')
def home(self):
return f'Lives in {self._city}, {self._country}'
Jan. 20, 2019
Comments: