| 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 | # Calculate Earth age in years |
| 24 | self.earth_age = seconds / self.EARTH_YEAR_IN_SECONDS |
| 25 | |
| 26 | def on_earth(self) -> float: |
| 27 | # Return age on Earth rounded to 2 decimal places |
| 28 | return round(self.earth_age, 2) |
| 29 | |
| 30 | def on_mercury(self) -> float: |
| 31 | # Calculate age on Mercury |
| 32 | age = self.earth_age / self.ORBITAL_PERIODS['mercury'] |
| 33 | return round(age, 2) |
| 34 | |
| 35 | def on_venus(self) -> float: |
| 36 | # Calculate age on Venus |
| 37 | age = self.earth_age / self.ORBITAL_PERIODS['venus'] |
| 38 | return round(age, 2) |
| 39 | |
| 40 | def on_mars(self) -> float: |
| 41 | # Calculate age on Mars |
| 42 | age = self.earth_age / self.ORBITAL_PERIODS['mars'] |
| 43 | return round(age, 2) |
| 44 | |
| 45 | def on_jupiter(self) -> float: |
| 46 | # Calculate age on Jupiter |
| 47 | age = self.earth_age / self.ORBITAL_PERIODS['jupiter'] |
| 48 | return round(age, 2) |
| 49 | |
| 50 | def on_saturn(self) -> float: |
| 51 | # Calculate age on Saturn |
| 52 | age = self.earth_age / self.ORBITAL_PERIODS['saturn'] |
| 53 | return round(age, 2) |
| 54 | |
| 55 | def on_uranus(self) -> float: |
| 56 | # Calculate age on Uranus |
| 57 | age = self.earth_age / self.ORBITAL_PERIODS['uranus'] |
| 58 | return round(age, 2) |
| 59 | |
| 60 | def on_neptune(self) -> float: |
| 61 | # Calculate age on Neptune |
| 62 | age = self.earth_age / self.ORBITAL_PERIODS['neptune'] |
| 63 | return round(age, 2) |
| 64 | # Handled Edge Cases: Negative seconds input |