Guest User

Untitled

a guest
Jan 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. from datetime import datetime, date
  2.  
  3. class Person():
  4. '''
  5. Create a new person!
  6. '''
  7.  
  8. def __init__(self, name, birthdate, birthplace, height):
  9. '''
  10. Initialize baseline attributes for person of interest
  11. '''
  12. self.name = name
  13. self.birthdate = birthdate
  14. self.birthplace = birthplace
  15. self.height = height
  16.  
  17. def introduce(self):
  18. '''
  19. Print out a simple introduction based on attributes
  20. '''
  21. print "Hi! My name is ", self.name, "and I was born in ", self.birthplace
  22.  
  23. def age(self):
  24. '''
  25. Calculate persons age based on inputted birthdate
  26. '''
  27. date_of_birth = datetime.strptime(self.birthdate, "%d %m %Y")
  28. today = date.today()
  29. 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