xas

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