更新
This commit is contained in:
23
Python-100-Days/Day01-15/Day04/for4.py
Normal file
23
Python-100-Days/Day01-15/Day04/for4.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
|
||||
输入一个正整数判断它是不是素数
|
||||
|
||||
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):
|
||||
if num % x == 0:
|
||||
is_prime = False
|
||||
break
|
||||
if is_prime and num != 1:
|
||||
print('%d是素数' % num)
|
||||
else:
|
||||
print('%d不是素数' % num)
|
||||
Reference in New Issue
Block a user