Python-100-Days/Day01-15/code/Day04/for4.py

21 lines
392 B
Python
Raw Normal View History

2018-03-02 00:09:06 +08:00
"""
输入一个正整数判断它是不是素数
Version: 0.1
Author: 骆昊
Date: 2018-03-01
"""
from math import sqrt
num = int(input('请输入一个正整数: '))
end = int(sqrt(num))
is_prime = True
for x in range(2, end + 1):
2019-05-03 21:17:36 +08:00
if num % x == 0:
is_prime = False
break
2018-03-02 00:09:06 +08:00
if is_prime and num != 1:
2019-05-03 21:17:36 +08:00
print('%d是素数' % num)
2018-03-02 00:09:06 +08:00
else:
2019-05-03 21:17:36 +08:00
print('%d不是素数' % num)