Created
November 20, 2021 02:20
-
-
Save mikeymop/b8c6d74762d234cf4d3233516b120784 to your computer and use it in GitHub Desktop.
Finds the year that you will be half someone's age.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
from math import floor | |
def max_ttd(birth_year): | |
this_year = date.today().year | |
age = this_year - birth_year | |
max_year = (100-age) + this_year | |
return max_year # agv age is 75, but 100 is safe | |
def year_to_age(birth_year, cur_year): | |
this_year = date.today().year | |
age = cur_year - birth_year | |
return age | |
def age_to_year(age): # 65 | |
this_year = date.today().year | |
return this_year - age # 1965 | |
def find_half_age(younger, older): | |
this_year = date.today().year | |
for year in range(this_year, int(max_ttd(older))): | |
dyounger = year_to_age(younger, year) | |
dolder = year_to_age(older, year) | |
if dyounger == floor(dolder/2): | |
return "In year {} you'll be half their age".format(year) | |
return "Older would be 100 first." | |
younger = age_to_year(int(input("How old is the younger person? "))) | |
older = age_to_year(int(input("How old is the older person? "))) | |
print(find_half_age(younger,older)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment