-
문자열 다루기 기본프로그래밍/알고리즘 2021. 3. 22. 16:09
def solution(s): if len(s) == 4 or len(s) == 6: for i in range(len(s)): if not s[i].isdigit(): return False return True else: return False
다른사람 풀이 1
def alpha_string46(s): return s.isdigit() and len(s) in (4, 6)
* if-else를 and로 바꿔서 True/False 반환
다른사람 풀이 2
def alpha_string46(s): try: int(s) except: return False return len(s) == 4 or len(s) == 6
* 풀면서 고민했었던 예외처리로 푸는 방법
728x90반응형LIST'프로그래밍 > 알고리즘' 카테고리의 다른 글
서울에서 김서방 찾기 (0) 2021.03.23 같은 숫자는 싫어 (0) 2021.03.23 가운데 글자 가져오기 (0) 2021.03.23 2016년 (0) 2021.03.22 프로그래머스 - k번째 수 (0) 2021.03.22