def func(n):
if n%2==0:
print("%d是偶数"%n)
else:
print("%d是奇数"%n)
func(11)
# 11是奇数
def func(n):
for i in range(1,n+1):
if i%2==0:
print(i)
func(10)
# 2
# 4
# 6
# 8
# 10
lst = [2,7,3,9,1,4]
def func(n):
x = n[0]
for i in n:
if i>x:
x=i
return x
print(func(lst))
# 9
lst = [2,7,3,9,1,4]
# print(sorted(lst,reverse=True))
# print(lst.sort())
# print(lst)
def func(n):
for i in range(len(n)-1):
for j in range(len(n)-i-1):
if n[j]
对正整数n,如果用2到x之间的所有整数去除,均无法整除,则n为质数
创新互联主营阳原网站建设的网络公司,主营网站建设方案,APP应用开发,阳原h5小程序制作搭建,阳原网站营销推广欢迎阳原等地区企业咨询
from math import sqrt
def func(n):
if n==1:
return '是质数'
else:
for i in range(2,int(sqrt(n))+1):
if n%i==0:
return '不是质数'
return '是质数'
print(func(2))
# 是质数
def func(n):
count=0
for i in range(1,n+1):
for j in range(2,int(sqrt(i)+1)):
if i%j==0:
break
else:
count=count+1
print(i,end=' ')
if count%4==0:
print("\n")
print(func(100))
# 1 2 3 5
#
# 7 11 13 17
#
# 19 23 29 31
#
# 37 41 43 47
#
# 53 59 61 67
#
# 71 73 79 83
#
# 89 97 None
'''
学习中遇到问题没人解答?小编创建了一个Python学习交流群:
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
def func(n):
if n==2:
return 2
for i in range(2,int(sqrt(n)+1)):
if n%i==0:
return func(n-1)
else:
print(n)
return func(n-1)
print(func(100))
# 97
# 89
# 83
# 79
# 73
# 71
# 67
# 61
# 59
# 53
# 47
# 43
# 41
# 37
# 31
# 29
# 23
# 19
# 17
# 13
# 11
# 7
# 5
# 3
# 2
def func(n):
newlist=[]
for i in range(0,len(n)+1,2):
newlist.append(n[i])
return newlist
list =['a','b','c','d','e','f','g','h','i','j','k']
print(func(list))
# ['a', 'c', 'e', 'g', 'i', 'k']
s = input("请输入一个数字:")
if len(s)==3:
result = int(s[0])**3 + int(s[1])**3 + int(s[2])**3
if int(s) == result:
print("是水仙花数字")
else:
print("不是水仙花数字")
else:
print("请输入三位数")