1152 (1) 썸네일형 리스트형 [백준] 1152: 단어의 개수 (Python) 1152번: 단어의 개수 문제 출처:https://www.acmicpc.net/problem/1152 코드 공유 (오답) sentence = input()words = sentence.split(" ")print(len(words)) 위의 경우는 맨 앞에 공백, 맨 뒤에 공백이 올 경우 오답이 도출된다. 그 이유는 앞 공백, 뒤 공백 모두 한 단어로 생각하기 때문에. split 함수를 잘못 사용했다.sentence = input()words = sentence.split(" ")if words[0] == "": print(len(words) -1)elif words[-1] == "": print(len(words) -1)else: print(len(words)) 위의 경우 또한 마찬.. 이전 1 다음