Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straight-forward solution in Clear category for Every Person is Unique by kkkkk
from datetime import date
class Person:
"""Contains information related to a person, name, job, etc."""
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
birth_units = list(map(int, birth_date.split(".")))
self._birth_date = date(birth_units[2], birth_units[1], birth_units[0])
self._job = job
self._working_years = working_years
self._monthly_salary = salary
self._country = country
self._city = city
self._gender = gender
def name(self):
"""Return name and surname separated by a whitespace."""
return f'{self._first_name} {self._last_name}'
def age(self):
"""Return number of fully lived years."""
today = date(2018, 1, 1)
diff_years = today.year - self._birth_date.year
if today.month < self._birth_date.month and \
today.day < self._birth_date.day:
diff_years -= 1
return diff_years
def work(self):
"""Return person's job in formatted sentence."""
pronoun = "Is"
if self._gender == "female":
pronoun = "She is"
elif self._gender == "male":
pronoun = "He is"
return f"{pronoun} a {self._job}"
def money(self):
"""Return money earned during working years.
Use whitspace for decimal places.
"""
salary = self._working_years * (self._monthly_salary * 12)
return f"{salary:,}".replace(',', ' ')
def home(self):
"""Return county and city where person lives."""
return f"Lives in {self._city}, {self._country}"
April 8, 2020
Comments: