future

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 Args:
7 seconds (int): The age of a person in seconds.
8 """
9
10 # Earth year in seconds
11 EARTH_YEAR_SECONDS = 31557600
12
13 # Orbital periods in 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 the given number of seconds.
28
29 Args:
30 seconds (int): The age in seconds.
31 """
32 # Edge Case: Negative seconds input
33 if seconds < 0:
34 raise ValueError("Seconds cannot be negative")
35
36 self.seconds = seconds
37 self.earth_years = seconds / self.EARTH_YEAR_SECONDS
38
39 def on_mercury(self) -> float:
40 """
41 Calculate the age on Mercury.
42
43 Returns:
44 float: The age on Mercury rounded to two decimal places.
45 """
46 age_on_mercury = self.earth_years / self.ORBITAL_PERIODS['mercury']
47 return round(age_on_mercury, 2)
48
49 def on_venus(self) -> float:
50 """
51 Calculate the age on Venus.
52
53 Returns:
54 float: The age on Venus rounded to two decimal places.
55 """
56 age_on_venus = self.earth_years / self.ORBITAL_PERIODS['venus']
57 return round(age_on_venus, 2)
58
59 def on_earth(self) -> float:
60 """
61 Calculate the age on Earth.
62
63 Returns:
64 float: The age on Earth rounded to two decimal places.
65 """
66 # This is just the Earth years, but rounded to two decimal places
67 return round(self.earth_years, 2)
68
69 def on_mars(self) -> float:
70 """
71 Calculate the age on Mars.
72
73 Returns:
74 float: The age on Mars rounded to two decimal places.
75 """
76 age_on_mars = self.earth_years / self.ORBITAL_PERIODS['mars']
77 return round(age_on_mars, 2)
78
79 def on_jupiter(self) -> float:
80 """
81 Calculate the age on Jupiter.
82
83 Returns:
84 float: The age on Jupiter rounded to two decimal places.
85 """
86 age_on_jupiter = self.earth_years / self.ORBITAL_PERIODS['jupiter']
87 return round(age_on_jupiter, 2)
88
89 def on_saturn(self) -> float:
90 """
91 Calculate the age on Saturn.
92
93 Returns:
94 float: The age on Saturn rounded to two decimal places.
95 """
96 age_on_saturn = self.earth_years / self.ORBITAL_PERIODS['saturn']
97 return round(age_on_saturn, 2)
98
99 def on_uranus(self) -> float:
100 """
101 Calculate the age on Uranus.
102
103 Returns:
104 float: The age on Uranus rounded to two decimal places.
105 """
106 age_on_uranus = self.earth_years / self.ORBITAL_PERIODS['uranus']
107 return round(age_on_uranus, 2)
108
109 def on_neptune(self) -> float:
110 """
111 Calculate the age on Neptune.
112
113 Returns:
114 float: The age on Neptune rounded to two decimal places.
115 """
116 age_on_neptune = self.earth_years / self.ORBITAL_PERIODS['neptune']
117 return round(age_on_neptune, 2)
118
119# 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.