본문 바로가기
프로그램

[파이썬] 문제 : 입력한 문자열에 동일한 두 문자가 연속되는지 검사

by 오디세이99 2022. 12. 14.
728x90
반응형

def question5(letters):
    same = False
    for i in range(len(letters)-1):    # len()-1인 것은 i와 i+1을 비교하므로
        if letters[i] == letters[i+1]: # i 와 i + 1 값 비교
            same = True                # 1개라고 같은게 있으면 True
            break                      # break로 for 반복문 종료
    return same

if __name__ == "__main__":
    user_input = str(input("5번 함수에 들어갈 문자열에 넣어주세요: "))
    print(question5(str(user_input)))

 

728x90
반응형

댓글