fistinz

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 # Handled Edge Cases: None for this constructor
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): The name of the planet
45
46 Returns:
47 float: The age on the specified planet, rounded to two decimal places
48
49 # Handled Edge Cases: None for this helper method
50 """
51 # Calculate Earth years
52 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
53 # Calculate age on the specified planet
54 planet_age = earth_years / self.ORBITAL_PERIODS[planet]
55 # Round to two decimal places
56 return round(planet_age, 2)
57
58 def on_mercury(self) -> float:
59 """
60 Calculate the age on Mercury.
61
62 Returns:
63 float: The age on Mercury in Earth years, rounded to two decimal places
64
65 # Handled Edge Cases: None for this method
66 """
67 return self._calculate_age_on_planet('mercury')
68
69 def on_venus(self) -> float:
70 """
71 Calculate the age on Venus.
72
73 Returns:
74 float: The age on Venus in Earth years, rounded to two decimal places
75
76 # Handled Edge Cases: None for this method
77 """
78 return self._calculate_age_on_planet('venus')
79
80 def on_earth(self) -> float:
81 """
82 Calculate the age on Earth.
83
84 Returns:
85 float: The age on Earth in Earth years, rounded to two decimal places
86
87 # Handled Edge Cases: None for this method
88 """
89 return self._calculate_age_on_planet('earth')
90
91 def on_mars(self) -> float:
92 """
93 Calculate the age on Mars.
94
95 Returns:
96 float: The age on Mars in Earth years, rounded to two decimal places
97
98 # Handled Edge Cases: None for this method
99 """
100 return self._calculate_age_on_planet('mars')
101
102 def on_jupiter(self) -> float:
103 """
104 Calculate the age on Jupiter.
105
106 Returns:
107 float: The age on Jupiter in Earth years, rounded to two decimal places
108
109 # Handled Edge Cases: None for this method
110 """
111 return self._calculate_age_on_planet('jupiter')
112
113 def on_saturn(self) -> float:
114 """
115 Calculate the age on Saturn.
116
117 Returns:
118 float: The age on Saturn in Earth years, rounded to two decimal places
119
120 # Handled Edge Cases: None for this method
121 """
122 return self._calculate_age_on_planet('saturn')
123
124 def on_uranus(self) -> float:
125 """
126 Calculate the age on Uranus.
127
128 Returns:
129 float: The age on Uranus in Earth years, rounded to two decimal places
130
131 # Handled Edge Cases: None for this method
132 """
133 return self._calculate_age_on_planet('uranus')
134
135 def on_neptune(self) -> float:
136 """
137 Calculate the age on Neptune.
138
139 Returns:
140 float: The age on Neptune in Earth years, rounded to two decimal places
141
142 # Handled Edge Cases: None for this method
143 """
144 return self._calculate_age_on_planet('neptune')
145
146# Handled Edge Cases: No specific edge cases were mentioned in the problem statement,
147# so this implementation assumes valid inputs as per the examples provided.
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.