Alone

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 relative to Earth years.
7
8 Attributes:
9 seconds (int): The age in seconds.
10 """
11
12 # Earth year in seconds
13 EARTH_YEAR_IN_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 number of seconds.
30
31 Args:
32 seconds (int): The age in seconds.
33
34 # Edge Case: Negative seconds input
35 # Edge Case: Zero seconds input
36 """
37 # Edge Case: Negative seconds input
38 if seconds < 0:
39 raise ValueError("Seconds cannot be negative")
40
41 # Edge Case: Zero seconds input
42 if seconds == 0:
43 self.seconds = 0
44 else:
45 self.seconds = seconds
46
47 def _calculate_age_on_planet(self, planet: str) -> float:
48 """
49 Calculate the age on a specific planet.
50
51 Args:
52 planet (str): The name of the planet (lowercase).
53
54 Returns:
55 float: The age on the specified planet, rounded to 2 decimal places.
56
57 # Edge Case: Invalid planet name
58 """
59 # Edge Case: Invalid planet name
60 if planet not in self.ORBITAL_PERIODS:
61 raise ValueError(f"Invalid planet name: {planet}")
62
63 earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS
64 planetary_years = earth_years / self.ORBITAL_PERIODS[planet]
65 return round(planetary_years, 2)
66
67 def on_mercury(self) -> float:
68 """
69 Calculate the age on Mercury.
70
71 Returns:
72 float: The age on Mercury, rounded to 2 decimal places.
73 """
74 return self._calculate_age_on_planet('mercury')
75
76 def on_venus(self) -> float:
77 """
78 Calculate the age on Venus.
79
80 Returns:
81 float: The age on Venus, rounded to 2 decimal places.
82 """
83 return self._calculate_age_on_planet('venus')
84
85 def on_earth(self) -> float:
86 """
87 Calculate the age on Earth.
88
89 Returns:
90 float: The age on Earth, rounded to 2 decimal places.
91 """
92 return self._calculate_age_on_planet('earth')
93
94 def on_mars(self) -> float:
95 """
96 Calculate the age on Mars.
97
98 Returns:
99 float: The age on Mars, rounded to 2 decimal places.
100 """
101 return self._calculate_age_on_planet('mars')
102
103 def on_jupiter(self) -> float:
104 """
105 Calculate the age on Jupiter.
106
107 Returns:
108 float: The age on Jupiter, rounded to 2 decimal places.
109 """
110 return self._calculate_age_on_planet('jupiter')
111
112 def on_saturn(self) -> float:
113 """
114 Calculate the age on Saturn.
115
116 Returns:
117 float: The age on Saturn, rounded to 2 decimal places.
118 """
119 return self._calculate_age_on_planet('saturn')
120
121 def on_uranus(self) -> float:
122 """
123 Calculate the age on Uranus.
124
125 Returns:
126 float: The age on Uranus, rounded to 2 decimal places.
127 """
128 return self._calculate_age_on_planet('uranus')
129
130 def on_neptune(self) -> float:
131 """
132 Calculate the age on Neptune.
133
134 Returns:
135 float: The age on Neptune, rounded to 2 decimal places.
136 """
137 return self._calculate_age_on_planet('neptune')
138
139# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
140# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
141# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
142# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
143# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
144# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
145# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
146# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
147# Handled Edge Cases: Negative seconds input, Zero seconds input, Invalid planet name
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.