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 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: Age on Mercury in Earth years, rounded to two decimal places
52 """
53 # Edge Case: Zero seconds results in zero years
54 age_on_mercury = self.earth_years / self.ORBITAL_PERIODS['mercury']
55 return round(age_on_mercury, 2)
56
57 def on_venus(self) -> float:
58 """
59 Calculate the age on Venus.
60
61 Returns:
62 float: Age on Venus in Earth years, rounded to two decimal places
63 """
64 # Edge Case: Zero seconds results in zero years
65 age_on_venus = self.earth_years / self.ORBITAL_PERIODS['venus']
66 return round(age_on_venus, 2)
67
68 def on_earth(self) -> float:
69 """
70 Calculate the age on Earth.
71
72 Returns:
73 float: Age on Earth in Earth years, rounded to two decimal places
74 """
75 # Edge Case: Zero seconds results in zero years
76 return round(self.earth_years, 2)
77
78 def on_mars(self) -> float:
79 """
80 Calculate the age on Mars.
81
82 Returns:
83 float: Age on Mars in Earth years, rounded to two decimal places
84 """
85 # Edge Case: Zero seconds results in zero years
86 age_on_mars = self.earth_years / self.ORBITAL_PERIODS['mars']
87 return round(age_on_mars, 2)
88
89 def on_jupiter(self) -> float:
90 """
91 Calculate the age on Jupiter.
92
93 Returns:
94 float: Age on Jupiter in Earth years, rounded to two decimal places
95 """
96 # Edge Case: Zero seconds results in zero years
97 age_on_jupiter = self.earth_years / self.ORBITAL_PERIODS['jupiter']
98 return round(age_on_jupiter, 2)
99
100 def on_saturn(self) -> float:
101 """
102 Calculate the age on Saturn.
103
104 Returns:
105 float: Age on Saturn in Earth years, rounded to two decimal places
106 """
107 # Edge Case: Zero seconds results in zero years
108 age_on_saturn = self.earth_years / self.ORBITAL_PERIODS['saturn']
109 return round(age_on_saturn, 2)
110
111 def on_uranus(self) -> float:
112 """
113 Calculate the age on Uranus.
114
115 Returns:
116 float: Age on Uranus in Earth years, rounded to two decimal places
117 """
118 # Edge Case: Zero seconds results in zero years
119 age_on_uranus = self.earth_years / self.ORBITAL_PERIODS['uranus']
120 return round(age_on_uranus, 2)
121
122 def on_neptune(self) -> float:
123 """
124 Calculate the age on Neptune.
125
126 Returns:
127 float: Age on Neptune in Earth years, rounded to two decimal places
128 """
129 # Edge Case: Zero seconds results in zero years
130 age_on_neptune = self.earth_years / self.ORBITAL_PERIODS['neptune']
131 return round(age_on_neptune, 2)
132
133 # Handled Edge Cases: Negative seconds (converted to positive), zero seconds
134 # Handled Edge Cases: Zero seconds for all planet methods
135 # Handled Edge Cases: Rounding to two decimal places for all methods
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.