Модератор, я опубликовал только ту часть задания на которую не могу найти решение.
Вот мой код выполнения задачи:
keyinput = input("Keyboard enter: ")
def valid_key(key):
if key.isupper() or not key.isalnum() or len(key) > 1 or key.isdigit():
print("KeyError")
else:
print(key)
valid_key(keyinput)
Вот полный текст задания:
The keyboard handler is a function which receives three parameters as input:
Key - the entered character on the keyboard.
isCaps (or is_caps) - boolean variable responsible for the enabled 'Caps Lock'. (by default false)
isShift (or is_shift) - boolean variable which is responsible for whether 'Shift' is pressed. (by default false)
Your task to write a function that returns the entered character.
Requirements for obtaining the 'key' variable:
Alphabetical characters must be a lowercase (e.x. 'a', not 'A')
It must be a character (e.x '2', not 2 or not [1,2,3])
It must be of unit length (e.x. 'a', not 'abc')
If the value does not satisfy the condition, return 'KeyError'
For example:
handler('a', True) # should return 'A' (because Caps-Lock)
handler('1', True) # should return '1' (because Сaps-Lock doesn't work here)
handler('a', False, True) # should return 'A' (because Shift)