Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('This program will tell you the year you turn 100 years old.')
- print('\nWhat is your name?')
- namecheck = 0
- while namecheck == 0:
- name = input('Name: ')
- if name.isalpha() and len(name) < 30:
- while True:
- name = name.title()
- yesno = input('Your name is {0}. Is this correct? (Yes/No) '.format(name))
- if yesno.lower() == 'yes':
- namecheck = 1
- break
- elif yesno.lower() == 'no':
- break
- else:
- print('Type "Yes" or "No".')
- if not name.isalpha():
- print('Please only use letters from the Roman alphabet.')
- if len(name) > 30:
- print('Please use less than 30 characters.')
- import datetime
- now = datetime.datetime.now() # current date and time
- print('\nHow old are you?')
- agecheck = 0
- birthday = 1
- while agecheck == 0:
- age = input('Age: ')
- if age.isdigit():
- if birthday == 0: # if computed birthday was wrong, user inputs it
- print('Which year were you born in?')
- while True:
- birthday = input('Year: ')
- if len(birthday) != 4:
- print('Please enter a valid date.')
- if int(age)+int(birthday) == now.year or int(age)+int(birthday)+1 == now.year:
- break
- else:
- print('Your entered age is {0}. This does not make sense with the year you have entered.'.format(age))
- else:
- birthday = now.year-int(age)
- if int(age) > 1: # differentiate between "year old" and "years old"
- year_s = 's'
- else:
- year_s = ''
- while True:
- yesno = input('You are {0} year{1} old and were born in {2}. Is this correct? (Yes/No) '.format(age,year_s,str(birthday)))
- if yesno.lower() == 'yes':
- agecheck = 1
- break
- elif yesno.lower() == 'no':
- print('Please re-enter your age and birthday.')
- birthday = 0
- break
- else:
- print('Type "Yes" or "No".')
- else:
- print('Please only use Roman numerals.')
- if int(age) < 100:
- turn_100 = int(birthday)+100
- years_until_100 = turn_100-now.year
- 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)))
- elif int(age) == 100 and now.year-int(birthday) == 100:
- print('{0}, you turned 100 years old this year! Congratulations!'.format(name))
- else:
- turn_100 = int(birthday)+100
- years_until_100 = (turn_100-now.year)*-1
- if years_until_100 > 1:
- year_s = 's'
- else:
- year_s = ''
- 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