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 Chocolater
class Person:
def __init__(self, first_name, last_name, birth_date, job,
working_years, salary, country, city, gender='unknown'):
self.first_name, self.last_name = first_name, last_name
self.birth_date, self.job = birth_date, job
self.working_years, self.salary = working_years, salary
self.country, self.city, self.gender = country, city, gender
def name(self):
return self.first_name + ' ' + self.last_name
def age(self):
if self.birth_date[:5] != '01.01':
return 2018 - int(self.birth_date[6:]) - 1
else:
return 2018 - int(self.birth_date[6:])
def work(self):
if self.gender == 'male':
result = 'He is a '
elif self.gender == 'female':
result = 'She is a '
else:
result = 'Is a '
return result + self.job
def money(self):
cash = str(self.working_years * self.salary * 12)
result = ''
while len(cash) > 0:
result = cash[-3:] + ' ' + result
cash = cash[:-3]
return result[:-1]
def home(self):
return 'Lives in ' + self.city + ', ' + self.country
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
def json_dict(d):
return dict((k, list(v)) for k, v in d.items())
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!")
June 8, 2018