let it go

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 an 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 # This ensures we can still calculate an age even if negative input is provided
37 self.seconds = abs(seconds)
38
39 # Edge Case: Handle zero seconds
40 # This is a valid input representing someone who is just born
41 if self.seconds == 0:
42 self.earth_years = 0
43 else:
44 self.earth_years = self.seconds / self.EARTH_YEAR_SECONDS
45
46 def on_mercury(self) -> float:
47 """
48 Calculate the age on Mercury.
49
50 Returns:
51 float: The age on Mercury in Earth years, rounded to two decimal places
52 """
53 # Edge Case: Zero seconds results in zero age
54 if self.earth_years == 0:
55 return 0.0
56 return round(self.earth_years / self.ORBITAL_PERIODS['mercury'], 2)
57
58 def on_venus(self) -> float:
59 """
60 Calculate the age on Venus.
61
62 Returns:
63 float: The age on Venus in Earth years, rounded to two decimal places
64 """
65 # Edge Case: Zero seconds results in zero age
66 if self.earth_years == 0:
67 return 0.0
68 return round(self.earth_years / self.ORBITAL_PERIODS['venus'], 2)
69
70 def on_earth(self) -> float:
71 """
72 Calculate the age on Earth.
73
74 Returns:
75 float: The age on Earth in Earth years, rounded to two decimal places
76 """
77 # Edge Case: Zero seconds results in zero age
78 if self.earth_years == 0:
79 return 0.0
80 return round(self.earth_years, 2)
81
82 def on_mars(self) -> float:
83 """
84 Calculate the age on Mars.
85
86 Returns:
87 float: The age on Mars in Earth years, rounded to two decimal places
88 """
89 # Edge Case: Zero seconds results in zero age
90 if self.earth_years == 0:
91 return 0.0
92 return round(self.earth_years / self.ORBITAL_PERIODS['mars'], 2)
93
94 def on_jupiter(self) -> float:
95 """
96 Calculate the age on Jupiter.
97
98 Returns:
99 float: The age on Jupiter in Earth years, rounded to two decimal places
100 """
101 # Edge Case: Zero seconds results in zero age
102 if self.earth_years == 0:
103 return 0.0
104 return round(self.earth_years / self.ORBITAL_PERIODS['jupiter'], 2)
105
106 def on_saturn(self) -> float:
107 """
108 Calculate the age on Saturn.
109
110 Returns:
111 float: The age on Saturn in Earth years, rounded to two decimal places
112 """
113 # Edge Case: Zero seconds results in zero age
114 if self.earth_years == 0:
115 return 0.0
116 return round(self.earth_years / self.ORBITAL_PERIODS['saturn'], 2)
117
118 def on_uranus(self) -> float:
119 """
120 Calculate the age on Uranus.
121
122 Returns:
123 float: The age on Uranus in Earth years, rounded to two decimal places
124 """
125 # Edge Case: Zero seconds results in zero age
126 if self.earth_years == 0:
127 return 0.0
128 return round(self.earth_years / self.ORBITAL_PERIODS['uranus'], 2)
129
130 def on_neptune(self) -> float:
131 """
132 Calculate the age on Neptune.
133
134 Returns:
135 float: The age on Neptune in Earth years, rounded to two decimal places
136 """
137 # Edge Case: Zero seconds results in zero age
138 if self.earth_years == 0:
139 return 0.0
140 return round(self.earth_years / self.ORBITAL_PERIODS['neptune'], 2)
141
142 # Handled Edge Cases: Negative seconds (converted to positive), zero seconds
143 # Handled Edge Cases: Zero seconds for all planet methods
144 # Handled Edge Cases: Proper rounding to two decimal places
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.