Guest User

Untitled

a guest
Jan 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. print('This program will tell you the year you turn 100 years old.')
  2.  
  3. print('\nWhat is your name?')
  4.  
  5. namecheck = 0
  6. while namecheck == 0:
  7. name = input('Name: ')
  8. if name.isalpha() and len(name) < 30:
  9. while True:
  10. name = name.title()
  11. yesno = input('Your name is {0}. Is this correct? (Yes/No) '.format(name))
  12. if yesno.lower() == 'yes':
  13. namecheck = 1
  14. break
  15. elif yesno.lower() == 'no':
  16. break
  17. else:
  18. print('Type "Yes" or "No".')
  19. if not name.isalpha():
  20. print('Please only use letters from the Roman alphabet.')
  21. if len(name) > 30:
  22. print('Please use less than 30 characters.')
  23.  
  24. import datetime
  25. now = datetime.datetime.now() # current date and time
  26.  
  27. print('\nHow old are you?')
  28.  
  29. agecheck = 0
  30. birthday = 1
  31. while agecheck == 0:
  32. age = input('Age: ')
  33. if age.isdigit():
  34. if birthday == 0: # if computed birthday was wrong, user inputs it
  35. print('Which year were you born in?')
  36. while True:
  37. birthday = input('Year: ')
  38. if len(birthday) != 4:
  39. print('Please enter a valid date.')
  40. if int(age)+int(birthday) == now.year or int(age)+int(birthday)+1 == now.year:
  41. break
  42. else:
  43. print('Your entered age is {0}. This does not make sense with the year you have entered.'.format(age))
  44. else:
  45. birthday = now.year-int(age)
  46. if int(age) > 1: # differentiate between "year old" and "years old"
  47. year_s = 's'
  48. else:
  49. year_s = ''
  50. while True:
  51. yesno = input('You are {0} year{1} old and were born in {2}. Is this correct? (Yes/No) '.format(age,year_s,str(birthday)))
  52. if yesno.lower() == 'yes':
  53. agecheck = 1
  54. break
  55. elif yesno.lower() == 'no':
  56. print('Please re-enter your age and birthday.')
  57. birthday = 0
  58. break
  59. else:
  60. print('Type "Yes" or "No".')
  61. else:
  62. print('Please only use Roman numerals.')
  63.  
  64. if int(age) < 100:
  65. turn_100 = int(birthday)+100
  66. years_until_100 = turn_100-now.year
  67. print('\n{0}, you are {1} year{2} old.\nIn {3} you will turn 100 years old.\nThis is {4} years away.'.format(name,age,year_s,str(turn_100),str(years_until_100)))
  68. elif int(age) == 100 and now.year-int(birthday) == 100:
  69. print('{0}, you turned 100 years old this year! Congratulations!'.format(name))
  70. else:
  71. turn_100 = int(birthday)+100
  72. years_until_100 = (turn_100-now.year)*-1
  73. if years_until_100 > 1:
  74. year_s = 's'
  75. else:
  76. year_s = ''
  77. print('\n{0}, you have already turned 100 years old. This was in {1}, {2} year{3} ago.'.format(name,turn_100,years_until_100,year_s))
Add Comment
Please, Sign In to add comment