CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day04/for4.py
Views: 729
1
"""
2
输入一个正整数判断它是不是素数
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-01
7
"""
8
from math import sqrt
9
10
num = int(input('请输入一个正整数: '))
11
end = int(sqrt(num))
12
is_prime = True
13
for x in range(2, end + 1):
14
if num % x == 0:
15
is_prime = False
16
break
17
if is_prime and num != 1:
18
print('%d是素数' % num)
19
else:
20
print('%d不是素数' % num)
21
22