goodagent

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 according to each planet's orbital period.
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: Negative seconds input
35 if seconds < 0:
36 raise ValueError("Seconds cannot be negative")
37 self.seconds = seconds
38
39 def _calculate_age_on_planet(self, planet: str) -> float:
40 """
41 Calculate the 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 2 decimal places.
48 """
49 # Edge Case: Invalid planet name
50 if planet not in self.ORBITAL_PERIODS:
51 raise ValueError(f"Invalid planet name: {planet}")
52
53 # Calculate Earth years from seconds
54 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
55
56 # Calculate age on the specified planet
57 planetary_age = earth_years / self.ORBITAL_PERIODS[planet]
58
59 # Round to 2 decimal places
60 return round(planetary_age, 2)
61
62 def on_mercury(self) -> float:
63 """
64 Calculate the age on Mercury.
65
66 Returns:
67 float: The age on Mercury, rounded to 2 decimal places.
68 """
69 return self._calculate_age_on_planet('mercury')
70
71 def on_venus(self) -> float:
72 """
73 Calculate the age on Venus.
74
75 Returns:
76 float: The age on Venus, rounded to 2 decimal places.
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, rounded to 2 decimal places.
86 """
87 return self._calculate_age_on_planet('earth')
88
89 def on_mars(self) -> float:
90 """
91 Calculate the age on Mars.
92
93 Returns:
94 float: The age on Mars, rounded to 2 decimal places.
95 """
96 return self._calculate_age_on_planet('mars')
97
98 def on_jupiter(self) -> float:
99 """
100 Calculate the age on Jupiter.
101
102 Returns:
103 float: The age on Jupiter, rounded to 2 decimal places.
104 """
105 return self._calculate_age_on_planet('jupiter')
106
107 def on_saturn(self) -> float:
108 """
109 Calculate the age on Saturn.
110
111 Returns:
112 float: The age on Saturn, rounded to 2 decimal places.
113 """
114 return self._calculate_age_on_planet('saturn')
115
116 def on_uranus(self) -> float:
117 """
118 Calculate the age on Uranus.
119
120 Returns:
121 float: The age on Uranus, rounded to 2 decimal places.
122 """
123 return self._calculate_age_on_planet('uranus')
124
125 def on_neptune(self) -> float:
126 """
127 Calculate the age on Neptune.
128
129 Returns:
130 float: The age on Neptune, rounded to 2 decimal places.
131 """
132 return self._calculate_age_on_planet('neptune')
133
134 # Handled Edge Cases: Negative seconds input, Invalid planet name
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.