편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2019.10.10

    문자열에서 특정문자 입력후 대문자로 바꾸기


    InputStr=input('Input a sentence :')
    Inputfind=input('Input a word for search :')
    findLength=len(Inputfind)
    
    Index=InputStr.find(Inputfind)
    
    
    
    if Index==-1:
        print('바꿀 문자가 없다.')
    else:
        beforeStr=InputStr[0:Index]
        changeStr=InputStr[Index:Index+findLength].upper()
        afterStr=InputStr[Index+findLength:]
        result=beforeStr+changeStr+afterStr
        print(result)
        print('A word "',Inputfind,'" apperas',InputStr.count(Inputfind),'times in the sentence.')
    

    위 코드대로 하면 첫번째 단어만 대문자로 바꾸고 그뒤는 실행이안되서,

    ex) power overwhelming 을 입력하면 powER overwhelming 이라고 나옵니다.

    powER ovERwhelming 이라고 나오게 하고싶은데 어떻게 고쳐야하나요.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2019.10.10

    문자열에서 특정문자 입력후 대문자로 바꾸기


    InputStr=input('Input a sentence :') Inputfind=input('Input a word for search :') findLength=len(Inputfind)

    Index=InputStr.find(Inputfind)

    if Index==-1: print('바꿀 문자가 없다.') else: beforeStr=InputStr[0:Index] changeStr=InputStr[Index:Index+findLength].upper() afterStr=InputStr[Index+findLength:] result=beforeStr+changeStr+afterStr print(result) print('A word "',Inputfind,'" apperas',InputStr.count(Inputfind),'times in the sentence.')

    위코드대로 하면 첫번째 단어만 대문자로 바꾸고 그뒤는 실행이안되서 ex) power overwhelming 을 입력하면 powER overwhelming 이라고 나옵니다 powER ovERwhelming 이라고 나오게 하고싶은데 어떻게 고쳐야하냐요