Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Every Person is Unique by alterGNU
import re
class Person:
def __init__(self, first_name, last_name, birth_date, job, working_years, salary, country, city, gender='unknown'):
#raise NotImplementedError
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):
return f"{self.first_name} {self.last_name}"
def age(self):
today = "01.01.2018"
td = today.split(".")
(td_y, td_m, td_d) = (int(td[2]), int(td[1]), int(td[0]))
bd = self.birth_date.split(".")
(bd_y, bd_m, bd_d) = (int(bd[2]), int(bd[1]), int(bd[0]))
return (td_y- bd_y-((td_m, td_d)<(bd_m, bd_d)))
def work(self):
dico = {"male":"He is", "female":"She is", "unknown":"Is"}
return f"{dico[self.gender]} a {self.job}"
def money(self):
return (re.sub(r"\B(?=(\d{3})+$)", " ", str(self.working_years*self.salary*12)))
def home(self):
return f"Lives in {self.city}, {self.country}"
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
p1 = Person("John", "Smith", "19.09.1979", "welder", 15, 3600, "Canada", "Vancouver", "male")
p2 = Person("Hanna Rose", "May", "05.12.1995", "designer", 2.2, 2150, "Austria", "Vienna")
assert p1.name() == "John Smith", "Name"
assert p1.age() == 38, "Age"
assert p2.work() == "Is a designer", "Job"
assert p1.money() == "648 000", "Money"
assert p2.home() == "Lives in Vienna, Austria", "Home"
print("Coding complete? Let's try tests!")
May 28, 2021