#依次输出五位数的每一位(由低位到高位)
i=12345
for a in range(5):
j=i%10
i=i//10
print(j)
#依次输出五位数的每一位(由高位到低位)
i=12345
for a in range(5,0,-1):
j=i//10**(a-1)
i=i%10**(a-1)
print(j)
#打印菱形
for i in range(-3,4):
j=abs(i)
print(‘ ‘*j,’*’*(7-2*j))
#打印对顶三角形
for i in range(-3,4):
j=abs(i)
print(‘ ‘*(3-j),’*’*(j*2+1))
#打印正方形
for i in range(4):
if i==0:
print(“n”*4)
elif i==3:
print (“n”*4)
else:
print(“n n”)
#100以内奇数的和
cout=0
for i in range(1,100,2):
cout+=i
print(cout)
#求1到5阶乘的和
sum=0
a=1
for i in range (1,6):
a*=i
sum+=a
print(sum)
#判断一个数是不是素数
a=int(input())
for i in range (2,int(a**0.5)):
if a%i==0:
print(‘这不是个质数’)
break
else:
print(‘这是质数’)
#求素数
for i in range(2,20):
for j in range (2,int(i**0.5)+1):
if i%j==0:
break
else:
print(i)
#九九乘法表
for i in range (1,10):
for j in range (1,i+1):
print(j,”*”,i,”=”,i*j,end=’\t’)
print()
#斐波那契数列第101项
a=0
b=1
i=1
while i<=101:
a,b=b,a+b
i+=1
print(a)
#将一列数按序排列,每五个一组输出
l=[1,342,5,5,3,5,6,8,5,4,3,3,4,5,5,544,4,3,34,434,4,4,54,5]
l.sort()
for i in range (int(len(l)/5)+1):
a=l[5*i:5*(i+1)]
print(a)
#输入一些数,判断最大数,并输出
l=int(input(‘>>’))
while True:
b=input(‘>>’)
if b==’q’:
break
elif l>=int(b):
print(l)
else:
l<int(b)
l=int(b)
print(l)
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/92879