-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticeday12.py
More file actions
44 lines (35 loc) · 809 Bytes
/
practiceday12.py
File metadata and controls
44 lines (35 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/10/27 10:44 PM
# @Author : Dora
# @File : practiceday12.py
#题目:判断101-200之间有多少个素数,并输出所有素数。
from math import sqrt
l = []
for i in range(101,200):
n = int(sqrt(i+1))
leap = 1
for x in range(2, n+1):
if i % x == 0:
leap = 0
if leap == 1:
l.append(i)
print(l,'Tatol is %d'%len(l))
# 参考答案
h = 0
leap = 1
from math import sqrt
from sys import stdout
for m in range(101,201):
k = int(sqrt(m + 1))
for i in range(2,k + 1):
if m % i == 0:
leap = 0
break
if leap == 1:
print('%-4d' % m)
h += 1
if h % 10 == 0:
print ('')
leap = 1
print ('The total is %d' % h)