Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, date
- class Person():
- '''
- Create a new person!
- '''
- def __init__(self, name, birthdate, birthplace, height):
- '''
- Initialize baseline attributes for person of interest
- '''
- self.name = name
- self.birthdate = birthdate
- self.birthplace = birthplace
- self.height = height
- def introduce(self):
- '''
- Print out a simple introduction based on attributes
- '''
- print "Hi! My name is ", self.name, "and I was born in ", self.birthplace
- def age(self):
- '''
- Calculate persons age based on inputted birthdate
- '''
- date_of_birth = datetime.strptime(self.birthdate, "%d %m %Y")
- today = date.today()
- print self.name, " is ", today.year - date_of_birth.year - ((today.month, today.day) < (date_of_birth.month, date_of_birth.day)), " years old."
Add Comment
Please, Sign In to add comment