-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube.py
67 lines (57 loc) · 2.48 KB
/
cube.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from my_array import Array
import random
class Cube():
# Metodo constructor del Cube
def __init__(self, rows, columns, depth, fill_value=None):
self.data = Array(rows)
for row in range(rows):
self.data[row] = Array(columns)
for column in range(columns):
self.data[row][column] = Array(depth, fill_value)
# Metodo para obtener la altura del Cube = cant de filas:
def __getheight__(self):
return len(self.data)
# Metodo para obtener el ancho del Cube = cant de columnas:
def __getwidth__(self):
return len(self.data[0])
# Metodo para obtener la profundidad del Cube
def __getdepth__(self):
return len(self.data[0][0])
# Metodo para obtener un valor en particular:
def __getitem__(self, r_index, c_index, d_index):
return self.data[r_index][c_index][d_index]
# Metodo para cambiar un valor en particular:
def __setitem__(self, r_index, c_index, d_index, value):
self.data[r_index][c_index][d_index] = value
# Metodo para devolver los valores en string:
def __str__(self):
result = ""
for row in range(self.__getheight__()):
if result != "":
result += "\n"
for column in range(self.__getwidth__()):
if result != "":
result += "\n"
for face in range(self.__getdepth__()):
if self.data[row][column][face] == None:
result += str(self.data[row][column][face]) + " | "
else:
if self.data[row][column][face] < 10:
result += " " + str(self.data[row][column][face]) + " | "
else:
result += str(self.data[row][column][face]) + " | "
return result
# Metodo para rellenar con numeros random mi cubo:
def __randomdata__(self):
for row in range(self.__getheight__()):
for column in range(self.__getwidth__()):
for face in range(self.__getdepth__()):
self.data[row][column][face] = random.randint(0,100)
# Metodo para sumar todos los valores:
def __sumdata__(self):
sum = 0
for row in range(self.__getheight__()):
for column in range(self.__getwidth__()):
for face in range(self.__getdepth__()):
sum += self.data[row][column][face]
return sum