weekends

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 into years for each planet considering their orbital periods.
7
8 Attributes:
9 seconds (int): The age in seconds.
10
11 Methods:
12 on_mercury(): Returns age on Mercury in Earth years.
13 on_venus(): Returns age on Venus in Earth years.
14 on_earth(): Returns age on Earth in Earth years.
15 on_mars(): Returns age on Mars in Earth years.
16 on_jupiter(): Returns age on Jupiter in Earth years.
17 on_saturn(): Returns age on Saturn in Earth years.
18 on_uranus(): Returns age on Uranus in Earth years.
19 on_neptune(): Returns age on Neptune in Earth years.
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 object with the given number of seconds.
40
41 Args:
42 seconds (int): The age in seconds. Must be non-negative.
43
44 Raises:
45 ValueError: If seconds is negative.
46 """
47 # Edge Case: Negative seconds input
48 if seconds < 0:
49 raise ValueError("Seconds cannot be negative")
50
51 self.seconds = seconds
52
53 def _calculate_age_on_planet(self, planet: str) -> float:
54 """
55 Helper method to calculate age on a specific planet.
56
57 Args:
58 planet (str): The name of the planet (lowercase).
59
60 Returns:
61 float: The age on the specified planet, rounded to 2 decimal places.
62 """
63 # Calculate Earth years from seconds
64 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
65
66 # Calculate age on the specified planet
67 age_on_planet = earth_years / self.ORBITAL_PERIODS[planet]
68
69 # Round to 2 decimal places
70 return round(age_on_planet, 2)
71
72 def on_mercury(self) -> float:
73 """
74 Calculates the age on Mercury.
75
76 Returns:
77 float: The age on Mercury in Earth years, rounded to 2 decimal places.
78 """
79 return self._calculate_age_on_planet('mercury')
80
81 def on_venus(self) -> float:
82 """
83 Calculates the age on Venus.
84
85 Returns:
86 float: The age on Venus in Earth years, rounded to 2 decimal places.
87 """
88 return self._calculate_age_on_planet('venus')
89
90 def on_earth(self) -> float:
91 """
92 Calculates the age on Earth.
93
94 Returns:
95 float: The age on Earth in Earth years, rounded to 2 decimal places.
96 """
97 return self._calculate_age_on_planet('earth')
98
99 def on_mars(self) -> float:
100 """
101 Calculates the age on Mars.
102
103 Returns:
104 float: The age on Mars in Earth years, rounded to 2 decimal places.
105 """
106 return self._calculate_age_on_planet('mars')
107
108 def on_jupiter(self) -> float:
109 """
110 Calculates the age on Jupiter.
111
112 Returns:
113 float: The age on Jupiter in Earth years, rounded to 2 decimal places.
114 """
115 return self._calculate_age_on_planet('jupiter')
116
117 def on_saturn(self) -> float:
118 """
119 Calculates the age on Saturn.
120
121 Returns:
122 float: The age on Saturn in Earth years, rounded to 2 decimal places.
123 """
124 return self._calculate_age_on_planet('saturn')
125
126 def on_uranus(self) -> float:
127 """
128 Calculates the age on Uranus.
129
130 Returns:
131 float: The age on Uranus in Earth years, rounded to 2 decimal places.
132 """
133 return self._calculate_age_on_planet('uranus')
134
135 def on_neptune(self) -> float:
136 """
137 Calculates the age on Neptune.
138
139 Returns:
140 float: The age on Neptune in Earth years, rounded to 2 decimal places.
141 """
142 return self._calculate_age_on_planet('neptune')
143
144 # 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.