Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
use datetime.strptime for age solution in Clear category for Every Person is Unique by mplichta
from datetime import datetime
class Person:
def __init__(self, first_name: str, last_name: str, birth_date: str, job: str, working_years: float,
salary: int, country: str, city: str, gender: str='unknown') -> None:
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
def name(self) -> str:
return f'{self.first_name} {self.last_name}'
def age(self) -> int:
current = datetime(2018, 1, 1)
birth = datetime.strptime(self.birth_date, '%d.%m.%Y')
# birth = date(*[int(x) for x in self.birth_date.split('.')][::-1])
# current = date(2018, 1, 1)
return (current - birth).days // 365
def work(self) -> str:
ret = 'Is'
if self.gender == 'male':
ret = 'He is'
elif self.gender == 'female':
ret = 'She is'
return f'{ret} a {self.job}'
def money(self) -> str:
return f'{12 * self.salary * self.working_years:,}'.replace(',', ' ')
def home(self) -> str:
return f'Lives in {self.city}, {self.country}'
June 7, 2018
Comments: