작성
·
3.7K
0
def value_to_key(dict):
dict_items = dict.items()list_value = list(dict.values())list_key = list(dict.keys())i = 0dict_2 = {}while i < len(list_key): dict_2[list_value[i]] = list_key[i] i += 1user_input = input("input the key : ")
return dict_2[user_input]
-----------------------------------------------(여기까지가 함수 식)
value_to_key(dict)
제가 쓴 코드는 이건데 print(dict_2)하면 {1: 'America', 2: 'China', 3: 'Korea', 4: 'Japan'}로 나오는데
user_input = 3 일때,
Traceback (most recent call last):
File "valuekey.py", line 20, in
value_to_key(dict)
File "valuekey.py", line 17, in value_to_key
return dict_2[user_input]
KeyError: '3'
요런게 뜨네요 어디가 문제인지 모르겠습니다.