基本上是这样的
class Key:
def __init__(self, pressed):
'''(Key, bool) -> NoneType
'''
self._pressed = pressed
def change_press_state(self):
self._pressed = not self._pressed
class KeyBoard:
def __init__(self, how_many):
'''(KeyBoard, int) -> NoneType
Makes a Keyboard of 'how_many' keys.
'''
self._keys = []
for i in range (0, how_many):
self._keys.append(KeyBoard(False))
def switch_status_of_key(self, index_of_key):
'''(KeyBoard) -> NoneType
Presses key if isn't and stops pressing key if it is.
'''
如何在用户想要在switch_status_of_key中切换的特定密钥上调用change_press_state? 我在想像
self._keys[key] = self._keys[key].flip()
但显然不是因为我收到错误。
答案 0 :(得分:0)
self._keys.append(KeyBoard(False))
应该是:
self._keys.append(Key(False))
和
def switch_status_of_key(self, index_of_key):
'''(KeyBoard) -> NoneType
Presses key if isn't and stops pressing key if it is.
'''
self._keys[index_of_key].change_press_state()