-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.py
executable file
·65 lines (49 loc) · 1.79 KB
/
person.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'''
An implementation of the "Persons of Interest" challenge exercise.
Created on Feb 10, 2015
@author: sql.sith
'''
from datetime import date
class Person(object):
species = 'Homo sapiens'
def __init__(self, first_name, last_name, city, state_or_province,
country, birth_date, email_address):
self.first_name = first_name
self.last_name = last_name
self.city = city
self.state_or_province = state_or_province
self.country = country
self.birth_date = birth_date
self.email_address = email_address
def has_email_address(self):
if self.email_address is None:
return(False)
else:
return(True)
def get_formatted_name(self):
return(self.first_name + ' ' + self.last_name)
def get_age(self):
today = date.today()
age = None
if today.month > self.birth_date.month:
age = today.year - self.birth_date.year
elif today.month < self.birth_date.month:
age = today.year - self.birth_date.year - 1
else: # same month
if today.day >= self.birth_date.day:
age = today.year - self.birth_date.year
else: # same month, but no birthday yet
age = today.year - self.birth_date.year - 1
return(age)
# main
chris = Person('Chris', 'Leonard', 'Cedar Rapids', 'IA',
'US', date(1964, 12, 25), '[email protected]')
charlie = Person('Charles', 'Coleman', 'Bertram', 'IA',
'US', date(1889, 12, 25), None)
print(chris.get_formatted_name())
print(chris.has_email_address())
print(chris.get_age())
print(charlie.get_formatted_name())
print(charlie.has_email_address())
print(charlie.get_age())
print("Chris is a {0}.".format(Person.species))