1,求水仙花数
1.for i in range(100,1000):
s=str(i)
if int(s[0])**3+int(s[1])**3+int(s[2])**3==i:
print(i)
2.for bai in range(1,10):
for shi in range(10):
for ge in range(10):
x=bai*100+shi*10+ge
if x==bai**3+shi**3+ge**3:
print(x)
3.for i in range(100,1000):
bai=i//100
shi=i%100//10
ge=i%10
if i==bai**3+shi**3+ge**3:
print(i)
2.倒序输入一组数据
str=input("请输入一串字符:")
for i in range(len(str)-1,-1,-1):
print('%c'%str[i],end='')
3.冒泡算法
score=[56,77,89,43,29,98,76,55,8,34,79,234,88]
print(score)
n=len(score)
for i in range(0,n-1):
for j in range(n-1,i,-1):
if score[j]<score[j-1]:
score[j],score[j-1]=score[j-1],score[j]
print(score)
4.求5的阶层
def f(number):
if number==1:
return 1
else:
return f(number-1)*number
print(f(5))
5.打印九九乘法口诀
for i in range(1,10):
for j in range(1,i+1):
print('%d*%d=%d'%(j,i,j*i),end=" ")
print('')