weekends

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 years.
8
9 Attributes:
10 seconds (int): The age in seconds.
11 earth_years (float): The age converted to Earth years.
12 """
13
14 # Earth year in seconds
15 EARTH_YEAR_SECONDS = 31557600
16
17 # Orbital periods relative to Earth years
18 ORBITAL_PERIODS = {
19 'mercury': 0.2408467,
20 'venus': 0.61519726,
21 'earth': 1.0,
22 'mars': 1.8808158,
23 'jupiter': 11.862615,
24 'saturn': 29.447498,
25 'uranus': 84.016846,
26 'neptune': 164.79132
27 }
28
229 def __init__(self, seconds: int) -> None:
3 pass
30 """
31 Initialize the SpaceAge object with the given age in seconds.
32
33 Args:
34 seconds (int): The age in seconds.
35
36 # Edge Case: Negative seconds input
37 # The class accepts negative seconds but will produce negative ages which is mathematically correct
38 # but may not make practical sense. No validation is done to prevent this as it's not specified.
39 """
40 self.seconds = seconds
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: The age on Mercury rounded to two decimal places.
49 """
50 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['mercury']
51 return round(age_on_planet, 2)
52
53 def on_venus(self) -> float:
54 """
55 Calculate the age on Venus.
56
57 Returns:
58 float: The age on Venus rounded to two decimal places.
59 """
60 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['venus']
61 return round(age_on_planet, 2)
62
63 def on_earth(self) -> float:
64 """
65 Calculate the age on Earth.
66
67 Returns:
68 float: The age on Earth rounded to two decimal places.
69 """
70 # Edge Case: Age on Earth is simply the earth_years attribute
71 # This is a direct calculation since Earth's orbital period is 1.0
72 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['earth']
73 return round(age_on_planet, 2)
74
75 def on_mars(self) -> float:
76 """
77 Calculate the age on Mars.
78
79 Returns:
80 float: The age on Mars rounded to two decimal places.
81 """
82 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['mars']
83 return round(age_on_planet, 2)
84
85 def on_jupiter(self) -> float:
86 """
87 Calculate the age on Jupiter.
88
89 Returns:
90 float: The age on Jupiter rounded to two decimal places.
91 """
92 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['jupiter']
93 return round(age_on_planet, 2)
94
95 def on_saturn(self) -> float:
96 """
97 Calculate the age on Saturn.
98
99 Returns:
100 float: The age on Saturn rounded to two decimal places.
101 """
102 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['saturn']
103 return round(age_on_planet, 2)
104
105 def on_uranus(self) -> float:
106 """
107 Calculate the age on Uranus.
108
109 Returns:
110 float: The age on Uranus rounded to two decimal places.
111 """
112 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['uranus']
113 return round(age_on_planet, 2)
114
115 def on_neptune(self) -> float:
116 """
117 Calculate the age on Neptune.
118
119 Returns:
120 float: The age on Neptune rounded to two decimal places.
121 """
122 age_on_planet = self.earth_years / self.ORBITAL_PERIODS['neptune']
123 return round(age_on_planet, 2)
124
125 # Handled Edge Cases: Negative seconds input, Direct calculation for Earth
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.