rockstar

Finished
11class SpaceAge:
2 """
3 A class to calculate the age of a person on different planets in our Solar System
4 based on their age in seconds.
5
6 The class provides methods for each planet that return the age on that planet
7 in Earth years, rounded to two decimal places.
8
9 Args:
10 seconds (int): The age in seconds
11 """
12
13 # Earth year in seconds
14 EARTH_YEAR_SECONDS = 31557600
15
16 # Orbital periods in 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
228 def __init__(self, seconds: int) -> None:
3 pass
29 """
30 Initialize the SpaceAge object with the given age in 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 # Edge Case: Store Earth years for reuse in calculations
38 self.earth_years = self.seconds / self.EARTH_YEAR_SECONDS
39
40 def on_mercury(self) -> float:
41 """
42 Calculate the age on Mercury.
43
44 Returns:
45 float: Age on Mercury in Earth years, rounded to two decimal places
46 """
47 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
48 age_on_mercury = self.earth_years / self.ORBITAL_PERIODS['mercury']
49 return round(age_on_mercury, 2)
50
51 def on_venus(self) -> float:
52 """
53 Calculate the age on Venus.
54
55 Returns:
56 float: Age on Venus in Earth years, rounded to two decimal places
57 """
58 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
59 age_on_venus = self.earth_years / self.ORBITAL_PERIODS['venus']
60 return round(age_on_venus, 2)
61
62 def on_earth(self) -> float:
63 """
64 Calculate the age on Earth.
65
66 Returns:
67 float: Age on Earth in Earth years, rounded to two decimal places
68 """
69 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
70 age_on_earth = self.earth_years / self.ORBITAL_PERIODS['earth']
71 return round(age_on_earth, 2)
72
73 def on_mars(self) -> float:
74 """
75 Calculate the age on Mars.
76
77 Returns:
78 float: Age on Mars in Earth years, rounded to two decimal places
79 """
80 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
81 age_on_mars = self.earth_years / self.ORBITAL_PERIODS['mars']
82 return round(age_on_mars, 2)
83
84 def on_jupiter(self) -> float:
85 """
86 Calculate the age on Jupiter.
87
88 Returns:
89 float: Age on Jupiter in Earth years, rounded to two decimal places
90 """
91 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
92 age_on_jupiter = self.earth_years / self.ORBITAL_PERIODS['jupiter']
93 return round(age_on_jupiter, 2)
94
95 def on_saturn(self) -> float:
96 """
97 Calculate the age on Saturn.
98
99 Returns:
100 float: Age on Saturn in Earth years, rounded to two decimal places
101 """
102 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
103 age_on_saturn = self.earth_years / self.ORBITAL_PERIODS['saturn']
104 return round(age_on_saturn, 2)
105
106 def on_uranus(self) -> float:
107 """
108 Calculate the age on Uranus.
109
110 Returns:
111 float: Age on Uranus in Earth years, rounded to two decimal places
112 """
113 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
114 age_on_uranus = self.earth_years / self.ORBITAL_PERIODS['uranus']
115 return round(age_on_uranus, 2)
116
117 def on_neptune(self) -> float:
118 """
119 Calculate the age on Neptune.
120
121 Returns:
122 float: Age on Neptune in Earth years, rounded to two decimal places
123 """
124 # Edge Case: Handle division by zero if orbital period is zero (not applicable here)
125 age_on_neptune = self.earth_years / self.ORBITAL_PERIODS['neptune']
126 return round(age_on_neptune, 2)
127
128 # Handled Edge Cases: Negative seconds, division by zero in orbital periods
Test NameStatus
test_age_on_earth
Pass
test_age_on_jupiter
Pass
test_age_on_mars
Pass
test_age_on_mercury
Pass
test_age_on_neptune
Pass
test_age_on_saturn
Pass
test_age_on_uranus
Pass
test_age_on_venus
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.