harrison

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