sourdough

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 planet in years, 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 problem doesn't specify behavior for negative inputs, but age can't be negative
35 # We'll allow it but the result will be negative ages
36 """
37 self.seconds = seconds
38
39 def _calculate_age_on_planet(self, planet: str) -> float:
40 """
41 Helper method to calculate age on a specific planet.
42
43 Args:
44 planet (str): Name of the planet
45
46 Returns:
47 float: Age on the planet rounded to 2 decimal places
48 """
49 # Calculate Earth years
50 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
51 # Convert to planet years
52 planet_years = earth_years / self.ORBITAL_PERIODS[planet]
53 # Round to 2 decimal places
54 return round(planet_years, 2)
55
56 def on_mercury(self) -> float:
57 """
58 Calculate age on Mercury.
59
60 Returns:
61 float: Age on Mercury in years, rounded to 2 decimal places
62 """
63 return self._calculate_age_on_planet('mercury')
64
65 def on_venus(self) -> float:
66 """
67 Calculate age on Venus.
68
69 Returns:
70 float: Age on Venus in years, rounded to 2 decimal places
71 """
72 return self._calculate_age_on_planet('venus')
73
74 def on_earth(self) -> float:
75 """
76 Calculate age on Earth.
77
78 Returns:
79 float: Age on Earth in years, rounded to 2 decimal places
80 """
81 return self._calculate_age_on_planet('earth')
82
83 def on_mars(self) -> float:
84 """
85 Calculate age on Mars.
86
87 Returns:
88 float: Age on Mars in years, rounded to 2 decimal places
89 """
90 return self._calculate_age_on_planet('mars')
91
92 def on_jupiter(self) -> float:
93 """
94 Calculate age on Jupiter.
95
96 Returns:
97 float: Age on Jupiter in years, rounded to 2 decimal places
98 """
99 return self._calculate_age_on_planet('jupiter')
100
101 def on_saturn(self) -> float:
102 """
103 Calculate age on Saturn.
104
105 Returns:
106 float: Age on Saturn in years, rounded to 2 decimal places
107 """
108 return self._calculate_age_on_planet('saturn')
109
110 def on_uranus(self) -> float:
111 """
112 Calculate age on Uranus.
113
114 Returns:
115 float: Age on Uranus in years, rounded to 2 decimal places
116 """
117 return self._calculate_age_on_planet('uranus')
118
119 def on_neptune(self) -> float:
120 """
121 Calculate age on Neptune.
122
123 Returns:
124 float: Age on Neptune in years, rounded to 2 decimal places
125 """
126 return self._calculate_age_on_planet('neptune')
127
128 # 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.