-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
45 lines (33 loc) · 1.33 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
45
# Write a class Block that creates a block (Duh..)
# Requirements
# The constructor should take an array as an argument, this will contain 3 integers of the form[width, length, height]
# from which the Block should be created.
# Define these methods:
# `get_width()` return the width of the `Block`
# `get_length()` return the length of the `Block`
# `get_height()` return the height of the `Block`
# `get_volume()` return the volume of the `Block`
# `get_surface_area()` return the surface area of the `Block`
# Examples
# b = Block([2, 4, 6]) -> create a `Block` object with a width of `2` a length of `4` and a height of `6`
# b.get_width() -> return 2
# b.get_length() -> return 4
# b.get_height() -> return 6
# b.get_volume() -> return 48
# b.get_surface_area() -> return 88
# Note: no error checking is needed
class Block:
def __init__(self, params):
self.width, self.length, self.height = params
self.volume = self.width * self.length * self.height
self.surface_area = 2 * self.length * (self.width + self.height) + 2 * self.height * self.width
def get_width(self):
return self.width
def get_length(self):
return self.length
def get_height(self):
return self.height
def get_volume(self):
return self.volume
def get_surface_area(self):
return self.surface_area