lexicon

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 given in seconds and converted to years based on the orbital periods
6 of the planets relative to Earth years.
7
8 Earth year is defined as 31,557,600 seconds.
9 """
10
11 # Earth year in seconds
12 EARTH_YEAR_SECONDS = 31557600
13
14 # Orbital periods in Earth years
15 ORBITAL_PERIODS = {
16 'mercury': 0.2408467,
17 'venus': 0.61519726,
18 'earth': 1.0,
19 'mars': 1.8808158,
20 'jupiter': 11.862615,
21 'saturn': 29.447498,
22 'uranus': 84.016846,
23 'neptune': 164.79132
24 }
25
226 def __init__(self, seconds: int) -> None:
3 pass
27 """
28 Initialize the SpaceAge object with the given age in seconds.
29
30 Parameters:
31 seconds (int): The age in seconds. Must be non-negative.
32
33 Raises:
34 ValueError: If seconds is negative.
35 """
36 # Edge Case: Negative seconds input
37 if seconds < 0:
38 raise ValueError("Seconds cannot be negative")
39
40 self.seconds = seconds
41
42 def _calculate_age_on_planet(self, planet: str) -> float:
43 """
44 Helper method to calculate age on a specific planet.
45
46 Parameters:
47 planet (str): The name of the planet (lowercase).
48
49 Returns:
50 float: The age on the specified planet, rounded to 2 decimal places.
51 """
52 # Calculate Earth years from seconds
53 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
54
55 # Calculate planetary years
56 planetary_years = earth_years / self.ORBITAL_PERIODS[planet]
57
58 # Round to 2 decimal places
59 return round(planetary_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 Mercury years, rounded to 2 decimal places.
67 """
68 return self._calculate_age_on_planet('mercury')
69
70 def on_venus(self) -> float:
71 """
72 Calculate the age on Venus.
73
74 Returns:
75 float: The age on Venus in Venus years, rounded to 2 decimal places.
76 """
77 return self._calculate_age_on_planet('venus')
78
79 def on_earth(self) -> float:
80 """
81 Calculate the age on Earth.
82
83 Returns:
84 float: The age on Earth in Earth years, rounded to 2 decimal places.
85 """
86 return self._calculate_age_on_planet('earth')
87
88 def on_mars(self) -> float:
89 """
90 Calculate the age on Mars.
91
92 Returns:
93 float: The age on Mars in Mars years, rounded to 2 decimal places.
94 """
95 return self._calculate_age_on_planet('mars')
96
97 def on_jupiter(self) -> float:
98 """
99 Calculate the age on Jupiter.
100
101 Returns:
102 float: The age on Jupiter in Jupiter years, rounded to 2 decimal places.
103 """
104 return self._calculate_age_on_planet('jupiter')
105
106 def on_saturn(self) -> float:
107 """
108 Calculate the age on Saturn.
109
110 Returns:
111 float: The age on Saturn in Saturn years, rounded to 2 decimal places.
112 """
113 return self._calculate_age_on_planet('saturn')
114
115 def on_uranus(self) -> float:
116 """
117 Calculate the age on Uranus.
118
119 Returns:
120 float: The age on Uranus in Uranus years, rounded to 2 decimal places.
121 """
122 return self._calculate_age_on_planet('uranus')
123
124 def on_neptune(self) -> float:
125 """
126 Calculate the age on Neptune.
127
128 Returns:
129 float: The age on Neptune in Neptune years, rounded to 2 decimal places.
130 """
131 return self._calculate_age_on_planet('neptune')
132
133 # Handled Edge Cases: Negative seconds input
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.