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