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