Algorithm/Programmers lv.1
[프로그래머스] 문자열 다루기 기본(문자열을 리스트로 바꾸기, isdigit)
채소기
2024. 8. 28. 22:46
https://school.programmers.co.kr/learn/courses/30/lessons/12918
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
처음엔 다음과 같이 풀었다.
def solution(s):
l = len(list(s))
if l == 4 or 6:
if s.isdigit():
return True
else:
return False
else:
return False
위 풀이에서 오류가 보이는지 확인해보자.
l == 4 or 6은 l == 4가 참이거나 6이 참이라는 의미가 된다. 결국에 무조건 참이라는 의미다.
따라서 아래와 같이 수정해준다..
def solution(s):
l = len(list(s))
if l == 4 or l == 6:
if s.isdigit():
return True
else:
return False
else:
return False
정답!