sn62

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 planetary years using the orbital periods of each planet.
7
8 Attributes:
9 seconds (int): The age in seconds.
10 earth_year_in_seconds (float): The number of seconds in an Earth year (31,557,600).
11 """
12
13 # Constants for planetary orbital periods in Earth years
14 EARTH_YEAR_IN_SECONDS = 31557600
15 ORBITAL_PERIODS = {
16 'mercury': 0.2408467,
17 'venus': 0.61519726,
18 'earth': 1.0,
19 'mars': 1.8808158,
20 'jupiter': 11.862615,
21 'saturn': 29.447498,
22 'uranus': 84.016846,
23 'neptune': 164.79132
24 }
25
226 def __init__(self, seconds: int) -> None:
3 pass
27 """
28 Initialize the SpaceAge object with the given number of seconds.
29
30 Args:
31 seconds (int): The age in seconds.
32
33 # Edge Case: Negative seconds input
34 # The problem doesn't specify how to handle negative inputs, but logically
35 # age cannot be negative. We'll allow it but the output will be negative too.
36 """
37 self.seconds = seconds
38
39 def _calculate_age_on_planet(self, planet: str) -> float:
40 """
41 Calculate the age on a specific planet.
42
43 Args:
44 planet (str): The name of the planet (lowercase).
45
46 Returns:
47 float: The age on the specified planet, rounded to 2 decimal places.
48 """
49 # Calculate Earth years from seconds
50 earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS
51
52 # Calculate planetary years by dividing Earth years by the planet's orbital period
53 planetary_years = earth_years / self.ORBITAL_PERIODS[planet]
54
55 # Round to 2 decimal places
56 return round(planetary_years, 2)
57
58 def on_mercury(self) -> float:
59 """
60 Calculate the age on Mercury.
61
62 Returns:
63 float: The age on Mercury in Mercury years, rounded to 2 decimal places.
64 """
65 return self._calculate_age_on_planet('mercury')
66
67 def on_venus(self) -> float:
68 """
69 Calculate the age on Venus.
70
71 Returns:
72 float: The age on Venus in Venus years, rounded to 2 decimal places.
73 """
74 return self._calculate_age_on_planet('venus')
75
76 def on_earth(self) -> float:
77 """
78 Calculate the age on Earth.
79
80 Returns:
81 float: The age on Earth in Earth years, rounded to 2 decimal places.
82 """
83 return self._calculate_age_on_planet('earth')
84
85 def on_mars(self) -> float:
86 """
87 Calculate the age on Mars.
88
89 Returns:
90 float: The age on Mars in Mars years, rounded to 2 decimal places.
91 """
92 return self._calculate_age_on_planet('mars')
93
94 def on_jupiter(self) -> float:
95 """
96 Calculate the age on Jupiter.
97
98 Returns:
99 float: The age on Jupiter in Jupiter years, rounded to 2 decimal places.
100 """
101 return self._calculate_age_on_planet('jupiter')
102
103 def on_saturn(self) -> float:
104 """
105 Calculate the age on Saturn.
106
107 Returns:
108 float: The age on Saturn in Saturn years, rounded to 2 decimal places.
109 """
110 return self._calculate_age_on_planet('saturn')
111
112 def on_uranus(self) -> float:
113 """
114 Calculate the age on Uranus.
115
116 Returns:
117 float: The age on Uranus in Uranus years, rounded to 2 decimal places.
118 """
119 return self._calculate_age_on_planet('uranus')
120
121 def on_neptune(self) -> float:
122 """
123 Calculate the age on Neptune.
124
125 Returns:
126 float: The age on Neptune in Neptune years, rounded to 2 decimal places.
127 """
128 return self._calculate_age_on_planet('neptune')
129
130 # 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.