[백준/Python] 11365 - !밀비 급일

orangesnail·2025년 4월 5일

백준

목록 보기
93/169

https://www.acmicpc.net/problem/11365


초기 코드

for문을 이용해 각 암호를 끝에서부터 한글자씩 출력해 주었다. 이때 글자마다 줄바꿈이 일어나는 것을 방지하기 위해 print() 함수 안에 end=""를 추가해준다.

while (True):
    password = input()

    if password == "END":
        break

    for i in range(len(password)-1, -1, -1):
        print(password[i], end="")
    print()

더 간단하게

for문을 이용하지 않고 슬라이싱을 이용해 훨씬 간단하게 표현할 수 있다.

while (True):
    password = input()

    if password == "END":
        break

    print(password[::-1])
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글