Pythton3实例
計(jì)算1-100之和
#add.py n = 0 sum = 0 for n in range(0,101):sum += n print(sum)實(shí)現(xiàn)99乘法法則
#mul.py i = 1 while i <= 9:j = 1while j <= i:mut = j*iprint("%d * %d = %d"%(j,i,mut),end=" ")j += 1print(" ")i += 1運(yùn)算結(jié)果:
robot@ubuntu:~/wangqinghe/python/20190827$ python3 mul.py
1 * 1 = 1?
1 * 2 = 2 2 * 2 = 4?
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9?
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16?
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25?
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36?
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49?
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64?
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
?
冒泡排序ptyhon版:
#bubble.py def bubble(li):temp = 0for i in range(len(li) - 1):for j in range(len(li) - 1 - i):if li[j] > li[j + 1]:temp = li[j]li[j] = li[j + 1]li[j + 1] = tempelse: temp = li[j+1]print(li)bubble([123,345,12,27,48,846,3458,239,9342])
?
運(yùn)行結(jié)果:
robot@ubuntu:~/wangqinghe/python$ python3.5 bubble.py
[12, 27, 48, 123, 239, 345, 846, 3458, 9342]
?
選擇排序:
#select.py a=[1,5,4,2,2,31,12,7,4] b = list(set(a)) c = [] for j in b:for i in a:if i == j:c.append(i) print(c)a = [1,23,457,234,68,234,47,925,345] print("primary a : ",a) a.sort() print(a)運(yùn)行結(jié)果:
robot@ubuntu:~/wangqinghe/python/20190827$ python3.5 select.py
[1, 2, 2, 4, 4, 5, 7, 12, 31]
primary a :? [1, 23, 457, 234, 68, 234, 47, 925, 345]
[1, 23, 47, 68, 234, 234, 345, 457, 925]
轉(zhuǎn)載于:https://www.cnblogs.com/wanghao-boke/p/11419974.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Pythton3实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英雄联盟手游怎么领标
- 下一篇: epoll函数