Guest User

Untitled

a guest
Mar 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #Create a program that asks the user to enter their name and their age.
  2. #Print out a message addressed to them that tells them the year that
  3. #they will turn 100 years old
  4. #!/usr/bin/python
  5.  
  6. class Person:
  7. 'This is a person object'
  8. person_headcount = 0
  9. year_now = 2018
  10. def __init__(self,name,age):
  11. if (isinstance(age,int)):
  12. self.name = name
  13. self.age = age
  14. self.person_headcount += 1
  15. else:
  16. print('age value should be explicit integer! use getPerson refill age')
  17. self.name = name
  18. self.age = 0
  19.  
  20. def getPerson(self,name,age):
  21. if (isinstance(age,int)):
  22. self.name = name
  23. self.age = age
  24. self.person_headcount += 1
  25. else:
  26. print('age value should be explicit integer! use getPerson refill age')
  27.  
  28. def putPerson(self):
  29. print('the person\'s name is %s, now is %d years old'%(self.name,self.age))
  30.  
  31. def answer(self):
  32. if(self.age <= 0):
  33. print('{:s} is not born yet'.format(self.name))
  34. else:
  35. print('Hi {:s}! You will become 100 years old in {:d}'.format(self.name, 2018 + 100 - self.age ))
  36.  
  37. def get_info():
  38. info = {'name':'', 'age':''}
  39. name = raw_input("Please input person's name:")
  40. age = int(raw_input("Please input person's age:"))
  41. info['name'] = name;
  42. info['age'] = age;
  43. return info
  44.  
  45. if Person.__module__ == '__main__':
  46. p_info = get_info()
  47. print("name:%s,age:%d"%(p_info['name'], p_info['age']))
  48. person = Person(p_info['name'],p_info['age'])
  49. person.putPerson()
  50. person.answer()
Add Comment
Please, Sign In to add comment