Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Full clean OOP Solution, and f-string with thousand separator, and datetime solution in Clear category for Every Person is Unique by bsquare
from datetime import datetime
DATE_FORMAT = "%d.%m.%Y"
CURRENT_DATE = "01.01.2018"
GENDER_UNKNOWN = 'unknown'
GENDER_MALE = 'male'
GENDER_FEMALE = 'female'
class Person:
def __init__(self, first_name, last_name, birth_date, job, working_years, salary, country, city, gender=GENDER_UNKNOWN):
self._first_name = first_name
self._last_name = last_name
self._birth_date = birth_date
self._job = job
self._working_years = working_years
self._salary = salary
self._country = country
self._city = city
self._gender = gender
self._current_date = datetime.strptime(CURRENT_DATE, DATE_FORMAT)
def name(self):
return f"{self._first_name} {self._last_name}"
def age(self):
birth_date = datetime.strptime(self._birth_date, DATE_FORMAT)
return (self._current_date - birth_date).days // 365.2425
def work(self):
prefix = 'Is' if self._gender == GENDER_UNKNOWN else ('He is', 'She is')[self._gender == GENDER_FEMALE]
return f"{prefix} a {self._job}"
def money(self):
return f'{12 * self._working_years * self._salary:,}'.replace(',', ' ')
def home(self):
return f"Lives in {self._city}, {self._country}"
Aug. 23, 2019