harrison

Finished
11class SpaceAge:
2 """
3 A class to calculate the age of a person on different planets in our Solar System.
4
5 The class takes an age in seconds and provides methods to calculate the age on various planets.
6 Each method returns the age on that planet in Earth years, rounded to two decimal places.
7
8 Attributes:
9 seconds (int): The age in seconds.
10 """
11
12 # Earth year in seconds
13 EARTH_YEAR_SECONDS = 31557600
14
15 # Orbital periods in 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 age in seconds.
30
31 Args:
32 seconds (int): The age in seconds.
33
34 # Edge Case: Negative seconds input
35 # Edge Case: Non-integer seconds input
36 """
37 # Edge Case: Negative seconds input
38 if seconds < 0:
39 raise ValueError("Seconds cannot be negative")
40
41 # Edge Case: Non-integer seconds input
42 if not isinstance(seconds, (int, float)):
43 raise TypeError("Seconds must be a number")
44
45 self.seconds = seconds
46
47 def _calculate_age_on_planet(self, planet: str) -> float:
48 """
49 Helper method to calculate age on a specific planet.
50
51 Args:
52 planet (str): The name of the planet.
53
54 Returns:
55 float: The age on the specified planet, rounded to two decimal places.
56 """
57 # Calculate Earth years
58 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
59
60 # Calculate age on the specified planet
61 planet_age = earth_years / self.ORBITAL_PERIODS[planet]
62
63 # Round to two decimal places
64 return round(planet_age, 2)
65
66 def on_mercury(self) -> float:
67 """
68 Calculate the age on Mercury.
69
70 Returns:
71 float: The age on Mercury in Earth years, rounded to two decimal places.
72 """
73 return self._calculate_age_on_planet('mercury')
74
75 def on_venus(self) -> float:
76 """
77 Calculate the age on Venus.
78
79 Returns:
80 float: The age on Venus in Earth years, rounded to two decimal places.
81 """
82 return self._calculate_age_on_planet('venus')
83
84 def on_earth(self) -> float:
85 """
86 Calculate the age on Earth.
87
88 Returns:
89 float: The age on Earth in Earth years, rounded to two decimal places.
90 """
91 return self._calculate_age_on_planet('earth')
92
93 def on_mars(self) -> float:
94 """
95 Calculate the age on Mars.
96
97 Returns:
98 float: The age on Mars in Earth years, rounded to two decimal places.
99 """
100 return self._calculate_age_on_planet('mars')
101
102 def on_jupiter(self) -> float:
103 """
104 Calculate the age on Jupiter.
105
106 Returns:
107 float: The age on Jupiter in Earth years, rounded to two decimal places.
108 """
109 return self._calculate_age_on_planet('jupiter')
110
111 def on_saturn(self) -> float:
112 """
113 Calculate the age on Saturn.
114
115 Returns:
116 float: The age on Saturn in Earth years, rounded to two decimal places.
117 """
118 return self._calculate_age_on_planet('saturn')
119
120 def on_uranus(self) -> float:
121 """
122 Calculate the age on Uranus.
123
124 Returns:
125 float: The age on Uranus in Earth years, rounded to two decimal places.
126 """
127 return self._calculate_age_on_planet('uranus')
128
129 def on_neptune(self) -> float:
130 """
131 Calculate the age on Neptune.
132
133 Returns:
134 float: The age on Neptune in Earth years, rounded to two decimal places.
135 """
136 return self._calculate_age_on_planet('neptune')
137
138 # Handled Edge Cases: Negative seconds input, Non-integer 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.