1、输出九九乘法口诀
for i in range(1,10): for j in range(1,i+1): print('{}*{}={}'.format(j,i,i*j),end=' ') print()
2、冒泡排序
li = [1,55,5,9,6,45,2] for i in range(len(li)-1): for j in range(len(li)-1-i): if li[j] > li[j+1]: li[j],li[j+1] = li[j+1],li[j] print(li)
3、计算1+2+3+4+100的和
s = 0 for i in range(101): s = s + i print("1+2+3+4+.....100={}".format(s))
4、有1,2,3,4个数字,能组成多少个互不相同且无重复的数字的三位数?都是多少?
s=0 for i in range(1,5): for j in range(1,5): for k in range(1,5): if i != j and j != k and i != k: s = s+1 print("互不相同且无重复的三位数为:{},{},{}".format(i,j,k)) print("组成互不相同且无重复的三位数共{}个".format(s)
5、斐波拉契数列,又称为黄金分割数列,指的是这样一个数列:0,1,1,2,3,5,8,13,21,34.........
a,b = 0,1 print(0,b,end=' ') while b < 100: a,b = b,a+b print(b,end=' ')
6、判断101-200之间有多少素数,并将所有的素数进行输出
count = 0 for i in range(101,200): flag = 1 for j in range(2,i): if i % j == 0: flag = 0 break if flag != 0: count += 1 print(i,end=' ') print('') print("101-200之间的素数共为:{}".format(count))