Merry

Finished
11class SpaceAge:
2 """
3 A class to calculate the age of a person on different planets in our Solar System.
4
5 The age is calculated based on the number of seconds provided, converting it to years
6 according to the orbital periods of various planets.
7
8 Attributes:
9 seconds (int): The age in seconds.
10 earth_year_seconds (float): Number of seconds in one Earth year (31,557,600).
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 the given number of seconds.
31
32 Args:
33 seconds (int): The age in seconds.
34
35 # Edge Case: Negative seconds - While not physically meaningful, we allow it as input
36 # Edge Case: Zero seconds - Valid input representing no time passed
37 """
38 self.seconds = seconds
39
40 def _calculate_age_on_planet(self, planet: str) -> float:
41 """
42 Calculate the age on a specific planet.
43
44 Args:
45 planet (str): The name of the planet (lowercase).
46
47 Returns:
48 float: The age on the specified planet, rounded to 2 decimal places.
49
50 # Edge Case: Invalid planet name - This is handled by the specific methods
51 """
52 # Calculate Earth years
53 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
54
55 # Convert to planet years
56 planet_years = earth_years / self.ORBITAL_PERIODS[planet]
57
58 # Round to 2 decimal places
59 return round(planet_years, 2)
60
61 def on_mercury(self) -> float:
62 """
63 Calculate the age on Mercury.
64
65 Returns:
66 float: The age on Mercury in years, rounded to 2 decimal places.
67 """
68 return self._calculate_age_on_planet('mercury')
69 # Handled Edge Cases: Negative seconds, Zero seconds
70
71 def on_venus(self) -> float:
72 """
73 Calculate the age on Venus.
74
75 Returns:
76 float: The age on Venus in years, rounded to 2 decimal places.
77 """
78 return self._calculate_age_on_planet('venus')
79 # Handled Edge Cases: Negative seconds, Zero seconds
80
81 def on_earth(self) -> float:
82 """
83 Calculate the age on Earth.
84
85 Returns:
86 float: The age on Earth in years, rounded to 2 decimal places.
87 """
88 return self._calculate_age_on_planet('earth')
89 # Handled Edge Cases: Negative seconds, Zero seconds
90
91 def on_mars(self) -> float:
92 """
93 Calculate the age on Mars.
94
95 Returns:
96 float: The age on Mars in years, rounded to 2 decimal places.
97 """
98 return self._calculate_age_on_planet('mars')
99 # Handled Edge Cases: Negative seconds, Zero seconds
100
101 def on_jupiter(self) -> float:
102 """
103 Calculate the age on Jupiter.
104
105 Returns:
106 float: The age on Jupiter in years, rounded to 2 decimal places.
107 """
108 return self._calculate_age_on_planet('jupiter')
109 # Handled Edge Cases: Negative seconds, Zero seconds
110
111 def on_saturn(self) -> float:
112 """
113 Calculate the age on Saturn.
114
115 Returns:
116 float: The age on Saturn in years, rounded to 2 decimal places.
117 """
118 return self._calculate_age_on_planet('saturn')
119 # Handled Edge Cases: Negative seconds, Zero seconds
120
121 def on_uranus(self) -> float:
122 """
123 Calculate the age on Uranus.
124
125 Returns:
126 float: The age on Uranus in years, rounded to 2 decimal places.
127 """
128 return self._calculate_age_on_planet('uranus')
129 # Handled Edge Cases: Negative seconds, Zero seconds
130
131 def on_neptune(self) -> float:
132 """
133 Calculate the age on Neptune.
134
135 Returns:
136 float: The age on Neptune in years, rounded to 2 decimal places.
137 """
138 return self._calculate_age_on_planet('neptune')
139 # Handled Edge Cases: Negative seconds, Zero 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.