我正在进行OOP练习,无法修复此错误。如果有人能帮助我,检查我的代码是否正确,这将是非常有帮助的
Traceback (most recent call last):
File "./main.py", line 12, in <module>
baldosa.rotar(270, "horario")
AttributeError: 'Baldosa' object has no attribute 'rotar'
class Camino:
def __init__(self,extremos,color):
self.extremos = extremos
self.color = color
self.conquistado = False
def __str__(self):
return "Camino: extremos =" + " " + str(self.extremos) + ", " + "color = " + self.color
def rotar(self,grados,sentido):
self.grados = grados
self.sentido = sentido
for i in range(0,2):
if sentido == "horario":
if grados == 90:
if self.extremos[i] == "N":
self.extremos[i] = "E"
elif self.extremos[i] == "E":
self.extremos[i] = "S"
elif self.extremos[i] == "S":
self.extremos[i] = "O"
elif self.extremos[i] == "O":
self.extremos[i] = "N"
elif self.extremos[i] == "F":
self.extremos[i] = "F"
elif grados == 180:
if self.extremos[i] == "N":
self.extremos[i] = "S"
elif self.extremos[i] == "E":
self.extremos[i] = "O"
elif self.extremos[i] == "S":
self.extremos[i] = "N"
elif self.extremos[i] == "O":
self.extremos[i] = "E"
elif self.extremos[i] == "F":
self.extremos[i] = "F"
elif grados == 270:
if self.extremos[i] == "N":
self.extremos[i] = "O"
elif self.extremos[i] == "E":
self.extremos[i] = "N"
elif self.extremos[i] == "S":
self.extremos[i] = "E"
elif self.extremos[i] == "O":
self.extremos[i] = "S"
elif self.extremos[i] == "F":
self.extremos[i] = "F"
elif sentido == "antihorario" :
if grados == 90:
if self.extremos[i] == "N":
self.extremos[i] = "O"
elif self.extremos[i] == "O":
self.extremos[i] = "S"
elif self.extremos[i] == "S":
self.extremos[i] = "E"
elif self.extremos[i] == "E":
self.extremos[i] = "N"
elif self.extremos[i] == "F":
self.extremos[i] = "F"
elif grados == 180:
if self.extremos[i] == "N":
self.extremos[i] = "S"
elif self.extremos[i] == "O":
self.extremos[i] = "E"
elif self.extremos[i] == "S":
self.extremos[i] = "N"
elif self.extremos[i] == "E":
self.extremos[i] = "O"
elif self.extremos[i] == "F":
self.extremos[i] = "F"
elif grados == 270:
if self.extremos[i] == "N":
self.extremos[i] = "E"
elif self.extremos[i] == "O":
self.extremos[i] = "N"
elif self.extremos[i] == "S":
self.extremos[i] = "O"
elif self.extremos[i] == "E":
self.extremos[i] = "S"
elif self.extremos[i] == "F":
self.extremos[i] = "F"
# Crea tu clase Baldosa
class Baldosa:
def __init__(self,caminos):
self.caminos = caminos
for cantidad in range(len(caminos)):
cantidad += 1
def camino(self,fila,col):
self.fila = fila
self.col = col
return "Baldosa: Num. de Caminos =" + str(self.camino) + "Ubicacion =" + "("+ str(self.fila) + "," + str(self.col) + ")"
之所以收到此消息,是因为您创建了类Baldosa的实例,然后尝试执行
rotar
方法。您只为Camino类的实例定义了它,因为它是在Camino类内部编写的。 因此,要么将rotar
方法添加到Baldosa类,要么创建Camina类的实例,即相关问题 更多 >
编程相关推荐