Kratos

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