unicode

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