python 学习1(数组冒泡排序,计算阶乘后面几个0)
计算阶乘后面有几个0:
'''
def func(num):
if(num==1):
return 1
else:
return num*func(num-1)
number=int(input("输入整数:"))
x=func(number)
string=str(x)
sum=0
for i in string:
if(i=='0'):
sum=sum+1
print(sum)
'''
'''
while True:
number=int(input("输入整数:"))
if(number<=0):
break
else:
sum=1
for num in range(1,number+1):
sum=sum*num
string=str(sum)
k=0
for i in string:
if(i=='0'):
k=k+1
print(k)
'''
#PS其实还有简单办法,就是只要计算含2,5的因子数就可以知道有多少个0,不是算法题,所以就不写代码了
while True:
arr = input("数组为:")
num = [int(n) for n in arr.split()] #将输入每个数以空格键隔开做成数组#
'''
while True:
try:
arr = input()
except:
break
这样好一些 '''
try:
arr = input()
except:
break
这样好一些 '''
if(arr=='a'):
break
else:
l=len(num)
for i in range(0,l-1):
for j in range(0,l-i-1):
if(num[j] > num[j+1]):
num[j] , num[j+1] = num[j+1] , num[j]
print(num)
'''
一维
arr = input("")
num = [int(n) for n in arr.split()]
print(num)
n = int(input()) //输入二维数组的行数和列数
line = [[0]*n]*n //初始化二维数组
for i in range(n):
line[i] = input().split(" ") //输入二维数组,同行数字用空格分隔,不同行则用回车换行
print(line) //打印二维数组
'''