seahawk

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 for each planet according to their orbital periods relative to Earth years.
7
8 Attributes:
9 seconds (int): The age in seconds.
10
11 Methods:
12 on_mercury(): Returns the age on Mercury.
13 on_venus(): Returns the age on Venus.
14 on_earth(): Returns the age on Earth.
15 on_mars(): Returns the age on Mars.
16 on_jupiter(): Returns the age on Jupiter.
17 on_saturn(): Returns the age on Saturn.
18 on_uranus(): Returns the age on Uranus.
19 on_neptune(): Returns the age on Neptune.
20 """
21
22 # Earth year in seconds
23 EARTH_YEAR_SECONDS = 31557600
24
25 # Orbital periods in Earth years
26 ORBITAL_PERIODS = {
27 'mercury': 0.2408467,
28 'venus': 0.61519726,
29 'earth': 1.0,
30 'mars': 1.8808158,
31 'jupiter': 11.862615,
32 'saturn': 29.447498,
33 'uranus': 84.016846,
34 'neptune': 164.79132
35 }
36
237 def __init__(self, seconds: int) -> None:
3 pass
38 """
39 Initializes the SpaceAge instance with the given number of seconds.
40
41 Args:
42 seconds (int): The age in seconds.
43 """
44 # Edge Case: Handle negative seconds by taking absolute value
45 self.seconds = abs(seconds)
46
47 def _calculate_age_on_planet(self, planet: str) -> float:
48 """
49 Helper method to calculate age on a specific planet.
50
51 Args:
52 planet (str): The name of the planet.
53
54 Returns:
55 float: The age on the specified planet, rounded to 2 decimal places.
56 """
57 # Edge Case: Handle division by zero if somehow EARTH_YEAR_SECONDS was 0
58 if self.EARTH_YEAR_SECONDS == 0:
59 return 0.0
60
61 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
62 planet_years = earth_years / self.ORBITAL_PERIODS[planet]
63 return round(planet_years, 2)
64
65 def on_mercury(self) -> float:
66 """
67 Calculates the age on Mercury.
68
69 Returns:
70 float: The age on Mercury, rounded to 2 decimal places.
71 """
72 return self._calculate_age_on_planet('mercury')
73
74 def on_venus(self) -> float:
75 """
76 Calculates the age on Venus.
77
78 Returns:
79 float: The age on Venus, rounded to 2 decimal places.
80 """
81 return self._calculate_age_on_planet('venus')
82
83 def on_earth(self) -> float:
84 """
85 Calculates the age on Earth.
86
87 Returns:
88 float: The age on Earth, rounded to 2 decimal places.
89 """
90 return self._calculate_age_on_planet('earth')
91
92 def on_mars(self) -> float:
93 """
94 Calculates the age on Mars.
95
96 Returns:
97 float: The age on Mars, rounded to 2 decimal places.
98 """
99 return self._calculate_age_on_planet('mars')
100
101 def on_jupiter(self) -> float:
102 """
103 Calculates the age on Jupiter.
104
105 Returns:
106 float: The age on Jupiter, rounded to 2 decimal places.
107 """
108 return self._calculate_age_on_planet('jupiter')
109
110 def on_saturn(self) -> float:
111 """
112 Calculates the age on Saturn.
113
114 Returns:
115 float: The age on Saturn, rounded to 2 decimal places.
116 """
117 return self._calculate_age_on_planet('saturn')
118
119 def on_uranus(self) -> float:
120 """
121 Calculates the age on Uranus.
122
123 Returns:
124 float: The age on Uranus, rounded to 2 decimal places.
125 """
126 return self._calculate_age_on_planet('uranus')
127
128 def on_neptune(self) -> float:
129 """
130 Calculates the age on Neptune.
131
132 Returns:
133 float: The age on Neptune, rounded to 2 decimal places.
134 """
135 return self._calculate_age_on_planet('neptune')
136
137 # Handled Edge Cases: Negative seconds, division by zero for EARTH_YEAR_SECONDS
138 # Handled Edge Cases: Negative seconds
139 # Handled Edge Cases: Negative seconds
140 # Handled Edge Cases: Negative seconds
141 # Handled Edge Cases: Negative seconds
142 # Handled Edge Cases: Negative seconds
143 # Handled Edge Cases: Negative seconds
144 # 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.