TEAMLAB-Lecture / python-101-for-data-science-by-pknu

1 stars 14 forks source link

Textprocessing1 질문입니다 #20

Open Seungjunsong opened 2 years ago

Seungjunsong commented 2 years ago

코드를 실행하면 this is an example 만 뜨고 뒤에 문구는 아예 뜨지 않는데 코드에서 잘못된 점을 잘 모르겠습니다.

textprocessing1
blissray commented 2 years ago

코드를 이미지가 아닌 텍스트로 붙여넣어 주시기 바랍니다.

Seungjunsong commented 2 years ago

#######################

Test Processing I

#######################

def normalize(input_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)

jsw6872 commented 2 years ago

while문에서 두번째 예시가 무한루프에 걸려서 계속 처리 중이다 보니 결과값이 나오지 않는 것 같습니다. while문에서 무한루프가 되지 않도록 수정이 필요해 보입니다!

Seungjunsong commented 2 years ago

감사합니다 그런데 혹시 왜 무한루프에 걸리게되는것인가요? 브레이크가 작동하지 않아서 그런가요?

jsw6872 commented 2 years ago

감사합니다 그런데 혹시 왜 무한루프에 걸리게되는것인가요? 브레이크가 작동하지 않아서 그런가요?

while문 안에서 변수 할당이 이루어지지 않은 부분이 있습니다! replace() 이 부분을 확인해보시면 좋을 것 같아요 !