Open Seungjunsong opened 2 years ago
코드를 이미지가 아닌 텍스트로 붙여넣어 주시기 바랍니다.
#######################
#######################
def normalize(input_string): """ 인풋으로 받는 스트링에서 정규화된 스트링을 반환함 아래의 요건들을 충족시켜야함
앞뒤 필요없는 띄어쓰기는 제거해야함
Parameters:
input_string (string): 영어로 된 대문자, 소문자, 띄어쓰기, 문장부호, 숫자로 이루어진 string
ex - "This is an example.", " EXTRA SPACE "
Returns:
normalized_string (string): 위 요건을 충족시킨 정규회된 string
ex - 'this is an example.'
Examples:
>>> import text_processing as tp
>>> input_string1 = "This is an example."
>>> tp.normalize(input_string1)
'this is an example.'
>>> input_string2 = " EXTRA SPACE "
>>> tp.normalize(input_string2)
'extra space'
"""
result_string = input_string.lower().strip() normalized_string = result_string i = " " j = " " if i in result_string: while i in result_string: result_string.replace(i , j) if i not in result_string: break return(normalized_string)
else: return(normalized_string)
if name == "main":
input_string = "This is an example."
print(normalize(input_string))
input_string = " EXTRA SPACE "
print(normalize(input_string))
def no_vowels(input_string): """ 인풋으로 받는 스트링에서 모든 모음 (a, e, i, o, u)를 제거시킨 스트링을 반환함
Parameters:
input_string (string): 영어로 된 대문자, 소문자, 띄어쓰기, 문장부호로 이루어진 string
ex - "This is an example."
Returns:
no_vowel_string (string): 모든 모음 (a, e, i, o, u)를 제거시킨 스트링
ex - "Ths s n xmpl."
Examples:
>>> import text_processing as tp
>>> input_string1 = "This is an example."
>>> tp.normalize(input_string1)
"Ths s n xmpl."
>>> input_string2 = "We love Python!"
>>> tp.normalize(input_string2)
''W lv Pythn!'
"""
no_vowel_string = ""
input_string.replace("e",no_vowel_string)
input_string.replace("i",no_vowel_string)
input_string.replace("o",no_vowel_string)
input_string.replace("u",no_vowel_string)
return (input_string)
result = no_vowels(input_string) print(input_string)
while문에서 두번째 예시가 무한루프에 걸려서 계속 처리 중이다 보니 결과값이 나오지 않는 것 같습니다. while문에서 무한루프가 되지 않도록 수정이 필요해 보입니다!
감사합니다 그런데 혹시 왜 무한루프에 걸리게되는것인가요? 브레이크가 작동하지 않아서 그런가요?
감사합니다 그런데 혹시 왜 무한루프에 걸리게되는것인가요? 브레이크가 작동하지 않아서 그런가요?
while문 안에서 변수 할당이 이루어지지 않은 부분이 있습니다! replace() 이 부분을 확인해보시면 좋을 것 같아요 !
코드를 실행하면 this is an example 만 뜨고 뒤에 문구는 아예 뜨지 않는데 코드에서 잘못된 점을 잘 모르겠습니다.