relax

Finished
11class SpaceAge:
2 """
3 A class to calculate the age of a person on different planets in our solar system
4 based on their age in seconds.
5
6 The class provides methods for each planet that return the age on that planet
7 in Earth years, rounded to two decimal places.
8 """
9
10 # Earth year in seconds
11 EARTH_YEAR_SECONDS = 31557600
12
13 # Orbital periods relative to Earth years
14 ORBITAL_PERIODS = {
15 'mercury': 0.2408467,
16 'venus': 0.61519726,
17 'earth': 1.0,
18 'mars': 1.8808158,
19 'jupiter': 11.862615,
20 'saturn': 29.447498,
21 'uranus': 84.016846,
22 'neptune': 164.79132
23 }
24
225 def __init__(self, seconds: int) -> None:
3 pass
26 """
27 Initialize the SpaceAge object with an age in seconds.
28
29 Args:
30 seconds (int): The age in seconds. Must be non-negative.
31
32 Raises:
33 ValueError: If seconds is negative.
34 """
35 # Edge Case: Handle negative seconds input
36 if seconds < 0:
37 raise ValueError("Seconds cannot be negative")
38
39 self.seconds = seconds
40 # Calculate Earth age in years
41 self.earth_years = seconds / self.EARTH_YEAR_SECONDS
42
43 def on_mercury(self) -> float:
44 """
45 Calculate the age on Mercury.
46
47 Returns:
48 float: Age on Mercury in Earth years, rounded to 2 decimal places.
49 """
50 age = self.earth_years / self.ORBITAL_PERIODS['mercury']
51 return round(age, 2)
52
53 def on_venus(self) -> float:
54 """
55 Calculate the age on Venus.
56
57 Returns:
58 float: Age on Venus in Earth years, rounded to 2 decimal places.
59 """
60 age = self.earth_years / self.ORBITAL_PERIODS['venus']
61 return round(age, 2)
62
63 def on_earth(self) -> float:
64 """
65 Calculate the age on Earth.
66
67 Returns:
68 float: Age on Earth in Earth years, rounded to 2 decimal places.
69 """
70 # Since we're calculating Earth years, we just return the pre-calculated value
71 return round(self.earth_years, 2)
72
73 def on_mars(self) -> float:
74 """
75 Calculate the age on Mars.
76
77 Returns:
78 float: Age on Mars in Earth years, rounded to 2 decimal places.
79 """
80 age = self.earth_years / self.ORBITAL_PERIODS['mars']
81 return round(age, 2)
82
83 def on_jupiter(self) -> float:
84 """
85 Calculate the age on Jupiter.
86
87 Returns:
88 float: Age on Jupiter in Earth years, rounded to 2 decimal places.
89 """
90 age = self.earth_years / self.ORBITAL_PERIODS['jupiter']
91 return round(age, 2)
92
93 def on_saturn(self) -> float:
94 """
95 Calculate the age on Saturn.
96
97 Returns:
98 float: Age on Saturn in Earth years, rounded to 2 decimal places.
99 """
100 age = self.earth_years / self.ORBITAL_PERIODS['saturn']
101 return round(age, 2)
102
103 def on_uranus(self) -> float:
104 """
105 Calculate the age on Uranus.
106
107 Returns:
108 float: Age on Uranus in Earth years, rounded to 2 decimal places.
109 """
110 age = self.earth_years / self.ORBITAL_PERIODS['uranus']
111 return round(age, 2)
112
113 def on_neptune(self) -> float:
114 """
115 Calculate the age on Neptune.
116
117 Returns:
118 float: Age on Neptune in Earth years, rounded to 2 decimal places.
119 """
120 age = self.earth_years / self.ORBITAL_PERIODS['neptune']
121 return round(age, 2)
122
123# 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.