agent

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 passed since birth,
6 and converted to planetary years using the orbital periods of each planet.
7
8 Attributes:
9 seconds (int): The age in seconds.
10 earth_year_seconds (float): The number of seconds in an 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 negative values
36 # as they might be used in certain calculations or comparisons.
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: Division by zero - Not applicable here as orbital periods are non-zero constants.
51 # Edge Case: Negative seconds - Handled by allowing negative values through.
52 """
53 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
54 planetary_years = earth_years / self.ORBITAL_PERIODS[planet]
55 return round(planetary_years, 2)
56
57 def on_mercury(self) -> float:
58 """
59 Calculate the age on Mercury.
60
61 Returns:
62 float: The age on Mercury in 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 the age on Venus.
69
70 Returns:
71 float: The age on Venus in 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 the age on Earth.
78
79 Returns:
80 float: The age on Earth in 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 the age on Mars.
87
88 Returns:
89 float: The age on Mars in 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 the age on Jupiter.
96
97 Returns:
98 float: The age on Jupiter in 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 the age on Saturn.
105
106 Returns:
107 float: The age on Saturn in 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 the age on Uranus.
114
115 Returns:
116 float: The age on Uranus in 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 the age on Neptune.
123
124 Returns:
125 float: The age on Neptune in years, rounded to 2 decimal places.
126 """
127 return self._calculate_age_on_planet('neptune')
128
129 # 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.