| 1 | 1 | class SpaceAge: |
| 2 | # Earth year in seconds |
| 3 | EARTH_YEAR_IN_SECONDS = 31557600 |
| 4 | |
| 5 | # Orbital periods in Earth years |
| 6 | ORBITAL_PERIODS = { |
| 7 | 'mercury': 0.2408467, |
| 8 | 'venus': 0.61519726, |
| 9 | 'earth': 1.0, |
| 10 | 'mars': 1.8808158, |
| 11 | 'jupiter': 11.862615, |
| 12 | 'saturn': 29.447498, |
| 13 | 'uranus': 84.016846, |
| 14 | 'neptune': 164.79132 |
| 15 | } |
| 16 | |
| 2 | 17 | def __init__(self, seconds: int) -> None: |
| 3 | | pass |
| 18 | """ |
| 19 | Initialize the SpaceAge object with an age in seconds. |
| 20 | |
| 21 | Args: |
| 22 | seconds (int): Age in seconds |
| 23 | |
| 24 | Edge Case: Negative seconds - While not physically meaningful, the calculation will proceed normally |
| 25 | Edge Case: Zero seconds - Results in age 0.0 on all planets |
| 26 | """ |
| 27 | # Edge Case: Non-integer input would be converted to integer |
| 28 | self.seconds = int(seconds) if not isinstance(seconds, int) else seconds |
| 29 | |
| 30 | def _calculate_age_on_planet(self, planet: str) -> float: |
| 31 | """ |
| 32 | Calculate age on a specific planet. |
| 33 | |
| 34 | Args: |
| 35 | planet (str): Name of the planet |
| 36 | |
| 37 | Returns: |
| 38 | float: Age on the planet rounded to 2 decimal places |
| 39 | """ |
| 40 | # Edge Case: Division by zero is avoided as all orbital periods are non-zero |
| 41 | earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS |
| 42 | planet_years = earth_years / self.ORBITAL_PERIODS[planet] |
| 43 | return round(planet_years, 2) |
| 44 | |
| 45 | def on_mercury(self) -> float: |
| 46 | """ |
| 47 | Calculate age on Mercury. |
| 48 | |
| 49 | Returns: |
| 50 | float: Age on Mercury in years, rounded to 2 decimal places |
| 51 | """ |
| 52 | return self._calculate_age_on_planet('mercury') |
| 53 | |
| 54 | def on_venus(self) -> float: |
| 55 | """ |
| 56 | Calculate age on Venus. |
| 57 | |
| 58 | Returns: |
| 59 | float: Age on Venus in years, rounded to 2 decimal places |
| 60 | """ |
| 61 | return self._calculate_age_on_planet('venus') |
| 62 | |
| 63 | def on_earth(self) -> float: |
| 64 | """ |
| 65 | Calculate age on Earth. |
| 66 | |
| 67 | Returns: |
| 68 | float: Age on Earth in years, rounded to 2 decimal places |
| 69 | """ |
| 70 | return self._calculate_age_on_planet('earth') |
| 71 | |
| 72 | def on_mars(self) -> float: |
| 73 | """ |
| 74 | Calculate age on Mars. |
| 75 | |
| 76 | Returns: |
| 77 | float: Age on Mars in years, rounded to 2 decimal places |
| 78 | """ |
| 79 | return self._calculate_age_on_planet('mars') |
| 80 | |
| 81 | def on_jupiter(self) -> float: |
| 82 | """ |
| 83 | Calculate age on Jupiter. |
| 84 | |
| 85 | Returns: |
| 86 | float: Age on Jupiter in years, rounded to 2 decimal places |
| 87 | """ |
| 88 | return self._calculate_age_on_planet('jupiter') |
| 89 | |
| 90 | def on_saturn(self) -> float: |
| 91 | """ |
| 92 | Calculate age on Saturn. |
| 93 | |
| 94 | Returns: |
| 95 | float: Age on Saturn in years, rounded to 2 decimal places |
| 96 | """ |
| 97 | return self._calculate_age_on_planet('saturn') |
| 98 | |
| 99 | def on_uranus(self) -> float: |
| 100 | """ |
| 101 | Calculate age on Uranus. |
| 102 | |
| 103 | Returns: |
| 104 | float: Age on Uranus in years, rounded to 2 decimal places |
| 105 | """ |
| 106 | return self._calculate_age_on_planet('uranus') |
| 107 | |
| 108 | def on_neptune(self) -> float: |
| 109 | """ |
| 110 | Calculate age on Neptune. |
| 111 | |
| 112 | Returns: |
| 113 | float: Age on Neptune in years, rounded to 2 decimal places |
| 114 | """ |
| 115 | return self._calculate_age_on_planet('neptune') |
| 116 | |
| 117 | # Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input, Division by zero avoidance |
| 118 | # Handled Edge Cases: Mercury calculation, Venus calculation, Earth calculation, Mars calculation, Jupiter calculation, Saturn calculation, Uranus calculation, Neptune calculation |