변수 r
p
q
에 대한 .val
을 제거하고 그들과 관련된 모든 속성 val
이 없습니다.
이제 어떻게 찾을 수 있습니까? 내장 기능은 dir
입니다. 당신이 볼 수
>>> r = 3
>>> dir(r)
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']
는 int
개체와 관련된 val
속성이 없습니다.
위의 문제를 해결하는 방법.
def Question4(T, r, p, q):
s, b = sorted([p, q]) // remove .val
while not s <= r <= b: // remove .val
r = r.left if s <= r else r.right // also int doesn't have .right or .left attribute, you need to define your own class to represent this custom data type
return r
T = [[0, 1, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[1, 0, 0, 0, 1],
[0, 0, 0, 0, 0]]
r = 3 // this is int object which don't have val attribute
p = 1
q = 4
Question4(T, r, p, q)
"p"와 "q"는 정수입니다. 정수에는'val' 속성이 없습니다. 그래서 당신은'p.val'이나'q.val'을 할 수 없습니다. – Kevin