couple

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