인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

ncsam1609's profile image
ncsam1609

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

2. Extract only numbers

이런 풀이는 어떤가요?

Written on

·

300

0

이런 풀이는 어떤가요? 앞에서도 res = res * 10 + int(x) 를 했었는데 자꾸 까먹고 잘 안들어오네요 이게ㅠㅠ
그러다보니 리스트도 만들고 for문도 한 번 더 사용했는데 이런식으로 코드를 짜면 안될까요?
 
s = input()
num_list = []

for i in s:
    if i.isdecimal():
        num_list.append(i)

num = ''
for j in num_list:
    if int(j):
        num += j

num = int(num)

cnt = 0
for i in range(1, num+1):
    if num % i == 0:
        cnt += 1

print(num)
print(cnt)
python코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

위 처럼해도 상관없습니다.

ncsam1609's profile image
ncsam1609

asked

Ask a question