-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
44 lines (33 loc) · 1.31 KB
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Now that we have a Block let's move on to something slightly more complex: a Sphere.
# Arguments for the constructor
# radius -> integer or float (do not round it)
# mass -> integer or float (do not round it)
# Methods to be defined
# get_radius() => radius of the Sphere (do not round it)
# get_mass() => mass of the Sphere (do not round it)
# get_volume() => volume of the Sphere (rounded to 5 place after the decimal)
# get_surface_area() => surface area of the Sphere (rounded to 5 place after the decimal)
# get_density() => density of the Sphere (rounded to 5 place after the decimal)
# Example
# ball = Sphere(2,50)
# ball.get_radius() -> 2
# ball.get_mass() -> 50
# ball.get_volume() -> 33.51032
# ball.get_surface_area() -> 50.26548
# ball.get_density() -> 1.49208
import math
class Sphere:
def __init__(self, radius, mass):
self.radius = radius
self.mass = mass
self.volume = round((4 / 3) * math.pi * self.radius**3, 5)
def get_radius(self):
return self.radius
def get_mass(self):
return self.mass
def get_volume(self):
return self.volume
def get_surface_area(self):
return round(4 * math.pi * self.radius**2, 5)
def get_density(self):
return round(self.mass / self.volume, 5)