python计算奇偶数以及是否能整除
#!/usr/bin/env python‘’’计算出0—20之间所有的偶数计算出0—20之间的所有奇数计算出一个整数是否可以被另外一个整数整除‘’’def oushu(x,y):a=[]for i in range(x,y+1):if i%2==0:a.append(i)else:passreturn adef jishu(x,y):a=[]i=xwhile ...
#!/usr/bin/env python
‘’’
计算出0—20之间所有的偶数
计算出0—20之间的所有奇数
计算出一个整数是否可以被另外一个整数整除
‘’’
def oushu(x,y):
a=[]
for i in range(x,y+1):
if i%2==0:
a.append(i)
else:
pass
return a
def jishu(x,y):
a=[]
i=x
while i<y+1:
if i%21:
a.append(i)
else:
pass
i=i+1
return a
#判断是否可以整除,可以被整除则为True,不能被整除则为False
def zhengchu(x,y):
if x%y0:
return True
elif y%x==0:
return True
else:
return False
if name"main":
print(oushu(0,20))
print(jishu(0,20))
new1=input(“please input the first number:”)
new2=input(“please input the second number:”)
a=zhengchu(int(new1),int(new2))
if aTrue:
print("{}和{}能够互相被整除".format(new1,new2))
else:
print("{}和{}不能够互相被整除".format(new1,new2))
更多推荐
所有评论(0)