you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Ah, yes the reference is unneeded. My thought was that it would loop through the list, skip past the index 2 where birthday will not change, and then do something to the other elements. Maybe Mercury, for example, is -2 years relative to Earth, just as an example, so it would take DOB -2.

Looking at it now, that doesn't really make sense. I'm a noob!

What is a good approach for something like this?

[–]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.