| 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 | # Edge Case: Negative seconds input |
| 19 | if seconds < 0: |
| 20 | raise ValueError("Seconds cannot be negative") |
| 21 | self.seconds = seconds |
| 22 | |
| 23 | def _calculate_age_on_planet(self, planet: str) -> float: |
| 24 | """Helper method to calculate age on a specific planet.""" |
| 25 | # Edge Case: Invalid planet name |
| 26 | if planet not in self.ORBITAL_PERIODS: |
| 27 | raise ValueError(f"Unknown planet: {planet}") |
| 28 | |
| 29 | # Calculate Earth years |
| 30 | earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS |
| 31 | |
| 32 | # Convert to planet years |
| 33 | planet_years = earth_years / self.ORBITAL_PERIODS[planet] |
| 34 | |
| 35 | # Round to two decimal places |
| 36 | return round(planet_years, 2) |
| 37 | |
| 38 | def on_mercury(self) -> float: |
| 39 | return self._calculate_age_on_planet('mercury') |
| 40 | |
| 41 | def on_venus(self) -> float: |
| 42 | return self._calculate_age_on_planet('venus') |
| 43 | |
| 44 | def on_earth(self) -> float: |
| 45 | return self._calculate_age_on_planet('earth') |
| 46 | |
| 47 | def on_mars(self) -> float: |
| 48 | return self._calculate_age_on_planet('mars') |
| 49 | |
| 50 | def on_jupiter(self) -> float: |
| 51 | return self._calculate_age_on_planet('jupiter') |
| 52 | |
| 53 | def on_saturn(self) -> float: |
| 54 | return self._calculate_age_on_planet('saturn') |
| 55 | |
| 56 | def on_uranus(self) -> float: |
| 57 | return self._calculate_age_on_planet('uranus') |
| 58 | |
| 59 | def on_neptune(self) -> float: |
| 60 | return self._calculate_age_on_planet('neptune') |
| 61 | |
| 62 | # Handled Edge Cases: Negative seconds input, Invalid planet name |