# 关于我们

## 新闻公告

< 返回

### python学习(7)

``````import math
def is_prime(num):
if num==1:
return False
if num==2:
return True
else:
for i in range(2,int(math.sqrt(num))+1):
if num%i == 0:
return False
return True
print(is_prime(13))
print(is_prime(12))
print(is_prime(2))

result = 0
for i in range(100):
if is_prime(i):
result += i
print(result)``````

``````#encoding=utf-8
import math
result = 0
for i in range(101):
if i%2 == 1:
result += i
print(result)``````

``````sum = 0
while True:
number = input("please input the number: ")
if number == ".":
break
else:
number = int(number)
if number%2 ==0:
sum += number
print(sum)      ``````

``````#encoding=utf-8
import math
for i in range(10,51):
if i%10 >=1 and i%10 <= 5:
print(i)``````

``````for i in range(10,51):
if str(i)[1] in "12345":
print(i)``````

``````for i in "1234":
for j in "12345":
print(int(i+j))``````

``````方式1：try--except
try:
for i in range(5):
for j in range(5):
if i==3 and j ==3:
raise
except:
print(1)
pass``````

``````def fun():
for i in range(5):
for j in range(5):
print(i,j)
if i==3 and j ==3:
return True
fun()``````

``````for i in range(5):
for j in range(5):
for k in range(5):
if i == j == k == 3:
break
else:
print (i, '----', j, '----', k)
else: continue
break
else: continue
break``````

/template/Home/Dawn/PC/Static