| 1 | 1 | class SpaceAge: |
| 2 | """ |
| 3 | A class to calculate the age of a person on different planets in our Solar System. |
| 4 | |
| 5 | The age is calculated based on the number of seconds provided, converting it to years |
| 6 | for each planet according to their orbital periods relative to Earth years. |
| 7 | |
| 8 | Attributes: |
| 9 | seconds (int): The age in seconds. |
| 10 | earth_year_seconds (float): The number of seconds in one Earth year (31,557,600). |
| 11 | """ |
| 12 | |
| 2 | 13 | def __init__(self, seconds: int) -> None: |
| 3 | | pass |
| 14 | """ |
| 15 | Initialize the SpaceAge class with the given number of seconds. |
| 16 | |
| 17 | Args: |
| 18 | seconds (int): The age in seconds. |
| 19 | """ |
| 20 | # Edge Case: Handle negative seconds by taking absolute value |
| 21 | self.seconds = abs(seconds) |
| 22 | self.earth_year_seconds = 31557600 |
| 23 | |
| 24 | def on_earth(self) -> float: |
| 25 | """ |
| 26 | Calculate the age on Earth. |
| 27 | |
| 28 | Returns: |
| 29 | float: The age on Earth in years, rounded to two decimal places. |
| 30 | """ |
| 31 | return round(self.seconds / self.earth_year_seconds, 2) |
| 32 | |
| 33 | def on_mercury(self) -> float: |
| 34 | """ |
| 35 | Calculate the age on Mercury. |
| 36 | |
| 37 | Returns: |
| 38 | float: The age on Mercury in years, rounded to two decimal places. |
| 39 | """ |
| 40 | return round(self.on_earth() / 0.2408467, 2) |
| 41 | |
| 42 | def on_venus(self) -> float: |
| 43 | """ |
| 44 | Calculate the age on Venus. |
| 45 | |
| 46 | Returns: |
| 47 | float: The age on Venus in years, rounded to two decimal places. |
| 48 | """ |
| 49 | return round(self.on_earth() / 0.61519726, 2) |
| 50 | |
| 51 | def on_mars(self) -> float: |
| 52 | """ |
| 53 | Calculate the age on Mars. |
| 54 | |
| 55 | Returns: |
| 56 | float: The age on Mars in years, rounded to two decimal places. |
| 57 | """ |
| 58 | return round(self.on_earth() / 1.8808158, 2) |
| 59 | |
| 60 | def on_jupiter(self) -> float: |
| 61 | """ |
| 62 | Calculate the age on Jupiter. |
| 63 | |
| 64 | Returns: |
| 65 | float: The age on Jupiter in years, rounded to two decimal places. |
| 66 | """ |
| 67 | return round(self.on_earth() / 11.862615, 2) |
| 68 | |
| 69 | def on_saturn(self) -> float: |
| 70 | """ |
| 71 | Calculate the age on Saturn. |
| 72 | |
| 73 | Returns: |
| 74 | float: The age on Saturn in years, rounded to two decimal places. |
| 75 | """ |
| 76 | return round(self.on_earth() / 29.447498, 2) |
| 77 | |
| 78 | def on_uranus(self) -> float: |
| 79 | """ |
| 80 | Calculate the age on Uranus. |
| 81 | |
| 82 | Returns: |
| 83 | float: The age on Uranus in years, rounded to two decimal places. |
| 84 | """ |
| 85 | return round(self.on_earth() / 84.016846, 2) |
| 86 | |
| 87 | def on_neptune(self) -> float: |
| 88 | """ |
| 89 | Calculate the age on Neptune. |
| 90 | |
| 91 | Returns: |
| 92 | float: The age on Neptune in years, rounded to two decimal places. |
| 93 | """ |
| 94 | return round(self.on_earth() / 164.79132, 2) |
| 95 | |
| 96 | # Handled Edge Cases: Negative seconds input |