함수 is_prime()

Jmnote (토론 | 기여)님의 2018년 7월 18일 (수) 19:47 판 (→‎Python)


함수 is_prime()

1 Python

def is_prime(x):
	if x < 2:
		return False
	for n in range(2, x-1):
		if x % n == 0:
			return False
	return True

for i in range(1,30):
    if is_prime(i):
        print( i, end=' ' )
# 2 3 5 7 11 13 17 19 23 29

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}