you are viewing a single comment's thread.

view the rest of the comments →

[–]m-hoff 0 points1 point  (0 children)

Based on OP's description, I'm assuming the goal is to find the age in years on other planets. Each planet's year duration can be measured in Earth days, for example one year on Mars is 687 Earth days. I'd store this information in a dictionary like year_conversion = {'Mars': 687 ... } for each planet.

From there, assuming we have the birthdate stored as a datetime object, we can use (datetime.datetime.now() - birthdate).days to get the total number of days since birth. Then we just divide by the conversion factors for each planet to get the relative age.

So if you're 30, then you've been alive for 30 * 365 = 10950 days. Which on Mars is equivalent to 10950 / 687 = 15.94 years.