| 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 given in seconds and converted to years based on the orbital periods |
| 6 | of the planets relative to Earth years. |
| 7 | |
| 8 | Earth year is defined as 31,557,600 seconds. |
| 9 | """ |
| 10 | |
| 11 | # Earth year in seconds |
| 12 | EARTH_YEAR_SECONDS = 31557600 |
| 13 | |
| 14 | # Orbital periods in Earth years |
| 15 | ORBITAL_PERIODS = { |
| 16 | 'mercury': 0.2408467, |
| 17 | 'venus': 0.61519726, |
| 18 | 'earth': 1.0, |
| 19 | 'mars': 1.8808158, |
| 20 | 'jupiter': 11.862615, |
| 21 | 'saturn': 29.447498, |
| 22 | 'uranus': 84.016846, |
| 23 | 'neptune': 164.79132 |
| 24 | } |
| 25 | |
| 2 | 26 | def __init__(self, seconds: int) -> None: |
| 3 | | pass |
| 27 | """ |
| 28 | Initialize the SpaceAge object with the given age in seconds. |
| 29 | |
| 30 | Args: |
| 31 | seconds (int): The age in seconds. Must be non-negative. |
| 32 | |
| 33 | Raises: |
| 34 | ValueError: If seconds is negative. |
| 35 | """ |
| 36 | # Edge Case: Negative seconds input |
| 37 | if seconds < 0: |
| 38 | raise ValueError("Seconds cannot be negative") |
| 39 | |
| 40 | self.seconds = seconds |
| 41 | |
| 42 | # Handled Edge Cases: Negative seconds input |
| 43 | |
| 44 | def on_mercury(self) -> float: |
| 45 | """ |
| 46 | Calculate the age on Mercury. |
| 47 | |
| 48 | Returns: |
| 49 | float: Age on Mercury in years, rounded to 2 decimal places. |
| 50 | """ |
| 51 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['mercury']), 2) |
| 52 | |
| 53 | # Handled Edge Cases: None for this method |
| 54 | |
| 55 | def on_venus(self) -> float: |
| 56 | """ |
| 57 | Calculate the age on Venus. |
| 58 | |
| 59 | Returns: |
| 60 | float: Age on Venus in years, rounded to 2 decimal places. |
| 61 | """ |
| 62 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['venus']), 2) |
| 63 | |
| 64 | # Handled Edge Cases: None for this method |
| 65 | |
| 66 | def on_earth(self) -> float: |
| 67 | """ |
| 68 | Calculate the age on Earth. |
| 69 | |
| 70 | Returns: |
| 71 | float: Age on Earth in years, rounded to 2 decimal places. |
| 72 | """ |
| 73 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['earth']), 2) |
| 74 | |
| 75 | # Handled Edge Cases: None for this method |
| 76 | |
| 77 | def on_mars(self) -> float: |
| 78 | """ |
| 79 | Calculate the age on Mars. |
| 80 | |
| 81 | Returns: |
| 82 | float: Age on Mars in years, rounded to 2 decimal places. |
| 83 | """ |
| 84 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['mars']), 2) |
| 85 | |
| 86 | # Handled Edge Cases: None for this method |
| 87 | |
| 88 | def on_jupiter(self) -> float: |
| 89 | """ |
| 90 | Calculate the age on Jupiter. |
| 91 | |
| 92 | Returns: |
| 93 | float: Age on Jupiter in years, rounded to 2 decimal places. |
| 94 | """ |
| 95 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['jupiter']), 2) |
| 96 | |
| 97 | # Handled Edge Cases: None for this method |
| 98 | |
| 99 | def on_saturn(self) -> float: |
| 100 | """ |
| 101 | Calculate the age on Saturn. |
| 102 | |
| 103 | Returns: |
| 104 | float: Age on Saturn in years, rounded to 2 decimal places. |
| 105 | """ |
| 106 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['saturn']), 2) |
| 107 | |
| 108 | # Handled Edge Cases: None for this method |
| 109 | |
| 110 | def on_uranus(self) -> float: |
| 111 | """ |
| 112 | Calculate the age on Uranus. |
| 113 | |
| 114 | Returns: |
| 115 | float: Age on Uranus in years, rounded to 2 decimal places. |
| 116 | """ |
| 117 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['uranus']), 2) |
| 118 | |
| 119 | # Handled Edge Cases: None for this method |
| 120 | |
| 121 | def on_neptune(self) -> float: |
| 122 | """ |
| 123 | Calculate the age on Neptune. |
| 124 | |
| 125 | Returns: |
| 126 | float: Age on Neptune in years, rounded to 2 decimal places. |
| 127 | """ |
| 128 | return round(self.seconds / (self.EARTH_YEAR_SECONDS * self.ORBITAL_PERIODS['neptune']), 2) |
| 129 | |
| 130 | # Handled Edge Cases: None for this method |