질의응답 게시판
introduction to python p.323 s8-2 질문입니다.
나 * 신 | 2024-01-29
def find_word(data,number):
new_data=data.sort(reverse=True)
start=0
end=len(data)-1
while start<=end:
mid=(end+start)//2
if new_data[mid]==number:
return mid
elif new_data[mid]<number:
end=mid-1
else:
start=mid+1
return -1
lists=[55,3,-12,2,51,-23,17,9,13,16,30,9]
print(lists)
num=int(input("찾고자 하는 수를 입력하세요: "))
index=find_word(lists,num)
if index==-1:
print("%d는 리스트에 존재하지 않는다"%num)
else:
print("%d는 리스트에 존재한다17"%num)
위 코드의 if new_data[mid]==number:에서 계속
'NoneType' object is not subscriptable 라고 에러가 발생하는데 정확히
어떤 에러인지 설명해주실 수 있나요?