Q.
문자열 s의 길이가 4 혹은 6이고, 숫자로만 구성돼있는지 확인해주는 함수, solution을 완성하세요. 예를 들어 s가 "a234"이면 False를 리턴하고 "1234"라면 True를 리턴하면 됩니다.
def solution(s):
answer = True
if len(s) == 4 or len(s)==6:
for i in s:
if i not in '0123456789':
answer = False
else:
answer = False
return answer
def alpha_string46(s):
return s.isdigit() and len(s) in (4, 6)
isdigit() 숫자인지 확인하기
isalpha() 알파벳인지 확인하기
'Algorithm' 카테고리의 다른 글
programmers #정수 제곱근 판별 (0) | 2021.07.21 |
---|---|
programmers # 행렬의 덧셈 (0) | 2021.07.20 |
programmers #정수 내림차순으로 배치하기 (0) | 2021.07.20 |
programmers #자연수 뒤집어 배열로 만들기 (0) | 2021.07.20 |
알고리즘 스터디 #스택과 큐 (0) | 2021.07.03 |