12 Sat
๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ
'''
https://programmers.co.kr/learn/courses/30/lessons/12918
๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ
[ํ์ด]
1. ๋ฌธ์์ด์ ๊ธธ์ด๊ฐ 4 ๋๋ 6์ด๋ฉด์ ์ซ์๋ก๋ง ๊ตฌ์ฑํ๊ธฐ
2. str์ int casting ํ ๋์ ์๋ฌ๋ก ๊ตฌ๋ถ.
'''
def solution(s):
try: return str(int(s)) == s and (len(s) == 4 or len(s) == 6)
except: return False
'''
isalpha์ isdigit์ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ๋ฌธ์์ด์ ๋ฌธ์, ์ซ์ ํ๋จ์ ํ ์ ์๋ค.
or ์ ์ด์ฉํ ๋น๊ต ๋ณด๋ค๋ in (4, 6)์ผ๋ก ๋น๊ตํ๋ฉด ๊ฐ๋จํ๋ค.
def alpha_string46(s):
return s.isdigit() and len(s) in (4, 6)
'''
Last updated
Was this helpful?