chris

Finished
11class SpaceAge:
2 """A class to calculate age on different planets based on Earth seconds.
3
4 This class takes an age in seconds and provides methods to calculate
5 the equivalent age on various planets in our solar system.
6
7 Attributes:
8 seconds (int): The age in seconds
9
10 Constants:
11 EARTH_YEAR_IN_SECONDS (int): Number of seconds in an Earth year (31,557,600)
12 """
13
14 # Earth year in seconds
15 EARTH_YEAR_IN_SECONDS = 31557600
16
17 # Orbital periods in Earth years
18 ORBITAL_PERIODS = {
19 'mercury': 0.2408467,
20 'venus': 0.61519726,
21 'earth': 1.0,
22 'mars': 1.8808158,
23 'jupiter': 11.862615,
24 'saturn': 29.447498,
25 'uranus': 84.016846,
26 'neptune': 164.79132
27 }
28
229 def __init__(self, seconds: int) -> None:
3 pass
30 """Initialize the SpaceAge object with seconds.
31
32 Args:
33 seconds (int): Age in seconds
34
35 Edge Case: Negative seconds - While not physically meaningful,
36 the implementation handles negative values by allowing them but
37 producing negative ages, which could be useful for relative calculations.
38 """
39 # Edge Case: Negative seconds
40 self.seconds = seconds
41
42 def _calculate_age_on_planet(self, planet: str) -> float:
43 """Helper method to calculate age on a specific planet.
44
45 Args:
46 planet (str): Name of the planet
47
48 Returns:
49 float: Age on the specified planet, rounded to 2 decimal places
50 """
51 # Calculate Earth years from seconds
52 earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS
53 # Calculate age on the specified planet
54 planet_age = earth_years / self.ORBITAL_PERIODS[planet]
55 # Round to 2 decimal places
56 return round(planet_age, 2)
57
58 def on_mercury(self) -> float:
59 """Calculate age on Mercury.
60
61 Returns:
62 float: Age on Mercury in Mercury years, rounded to 2 decimal places
63 """
64 return self._calculate_age_on_planet('mercury')
65
66 def on_venus(self) -> float:
67 """Calculate age on Venus.
68
69 Returns:
70 float: Age on Venus in Venus years, rounded to 2 decimal places
71 """
72 return self._calculate_age_on_planet('venus')
73
74 def on_earth(self) -> float:
75 """Calculate age on Earth.
76
77 Returns:
78 float: Age on Earth in Earth years, rounded to 2 decimal places
79 """
80 return self._calculate_age_on_planet('earth')
81
82 def on_mars(self) -> float:
83 """Calculate age on Mars.
84
85 Returns:
86 float: Age on Mars in Mars years, rounded to 2 decimal places
87 """
88 return self._calculate_age_on_planet('mars')
89
90 def on_jupiter(self) -> float:
91 """Calculate age on Jupiter.
92
93 Returns:
94 float: Age on Jupiter in Jupiter years, rounded to 2 decimal places
95 """
96 return self._calculate_age_on_planet('jupiter')
97
98 def on_saturn(self) -> float:
99 """Calculate age on Saturn.
100
101 Returns:
102 float: Age on Saturn in Saturn years, rounded to 2 decimal places
103 """
104 return self._calculate_age_on_planet('saturn')
105
106 def on_uranus(self) -> float:
107 """Calculate age on Uranus.
108
109 Returns:
110 float: Age on Uranus in Uranus years, rounded to 2 decimal places
111 """
112 return self._calculate_age_on_planet('uranus')
113
114 def on_neptune(self) -> float:
115 """Calculate age on Neptune.
116
117 Returns:
118 float: Age on Neptune in Neptune years, rounded to 2 decimal places
119 """
120 return self._calculate_age_on_planet('neptune')
121
122 # Handled Edge Cases: Negative seconds
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.