python实例 89,90
生活随笔
收集整理的這篇文章主要介紹了
python实例 89,90
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
89.電話數據加密
?90.題目:列表的使用實例
89.電話數據加密
題目:某個公司采用公用電話傳遞數據,數據是四位的整數,在傳遞過程中是加密的,加密規則如下:每位數字都加上5,然后用和除以10的余數代替該數字,再將第一位和第四位交換,第二位和第三位交換。
#89 n=int(input("請輸入一個四位整數:")) n = str(n) a=[] for i in range(4):a.append((int(n[i])+5)%10) a[0],a[3]=a[3],a[0] a[1],a[2]=a[2],a[1] print("".join('%s' %s for s in a))返回:
?90.題目:列表的使用實例
#90 #list #新建列表 testList=[10086,'中國移動',[1,2,4,5]] #訪問列表長度 print(len(testList)) #到列表結尾 print(testList[1:]) #向列表添加元素 testList.append('i\'m new here!') print(len(testList)) print(testList[-1]) #彈出列表的最后一個元素 print(testList.pop(1)) print(len(testList)) print(testList) #list comprehension #后面有介紹,暫時掠過 matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(matrix) print(matrix[1]) col2 = [row[1] for row in matrix]#get a column from a matrix print(col2) col2even = [row[1] for row in matrix if row[1] % 2 == 0]#filter odd item print(col2even)返回:
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python实例 89,90的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB使用教程(4)——悄悄滴上手
- 下一篇: python实例 85,86