Notice
Recent Posts
Recent Comments
Link
관리 메뉴

Star_project

[인프런] 3.탐색&시뮬레이션(string, 1차원, 2차원 리스트 탐색 ) 2.숫자만추출 본문

코딩테스트/Python

[인프런] 3.탐색&시뮬레이션(string, 1차원, 2차원 리스트 탐색 ) 2.숫자만추출

star빛 2022. 7. 12. 16:57
2. 숫자만 추출
import sys
sys.stdin=open("pythonalgorithm/섹션 3/2. 숫자만 추출/in1.txt","rt")
a=input()
res=cnt=0
for i in a:
    if i.isdecimal():
        res=res*10+int(i)
print(res)
for i in range(1,res+1):
    if res%i==0:
        cnt+=1
print(cnt)
  • isdecimal()

Definition and Usage

The isdecimal() method returns True if all the characters are decimals (0-9).

This method is used on unicode objects.

출처 : https://www.w3schools.com/python/ref_string_isdecimal.asp#:~:text=The%20isdecimal()%20method%20returns,is%20used%20on%20unicode%20objects. 

 

Python String isdecimal() Method

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

  • 약수의 개수를 구할 때 for 범위는 range(1, 해당값+1)