幾個python運維面試題及答案

1.生成隨機的20個ID
ID格式要求:
時間戳_三位隨機數字號碼_8位隨機小寫字母
1506571959_089_xxkeabef
datetime.datetime.now().timestamp() 返回的是時間戳,但是帶微秒
2.判斷密碼強弱
要求密碼必須由 10-15位 指定字符組成:
十進制數字
大寫字母
小寫字母
下劃線
要求四種類型的字符都要出現才算合法的強密碼
例如:Aatb32_67mnq,其中包含大寫字母、小寫字母、數字和下劃線,是合格的強密碼
第一題的答案
import datetime
idlist =[]
for _ in range(20):
????s1=datetime.datetime.now().timestamp()
????s2=”.join([str(random.randint(0,9)) for _ in range(3)])
????s3=”.join([chr(random.randint(97,122)) for _ in range(8)])
????idlist.append(str(int(s1))+’_’+s2+’_’+s3)
print(idlist)
運行效果
[‘1506737163_551_jlgwhswi’, ‘1506737163_957_tsobyhnr’, ‘1506737163_535_gwonnyen’, ‘1506737163_318_lxhfwcak’, ‘1506737163_425_pqzdrvlg’, ‘1506737163_195_lumkmsot’, ‘1506737163_880_nfpshuiv’, ‘1506737163_856_mavmfkrz’, ‘1506737163_708_xzbeezok’, ‘1506737163_937_sxpxhefr’, ‘1506737163_210_vfstxgqs’, ‘1506737163_501_hwezvcme’, ‘1506737163_279_wrhacjez’, ‘1506737163_161_wgqtnyht’, ‘1506737163_077_iwrshxwh’, ‘1506737163_434_jcezllwg’, ‘1506737163_297_tjzjwxay’, ‘1506737163_858_gnqjkolw’, ‘1506737163_475_xjaanwkm’, ‘1506737163_078_pudqxphx’]
第二題的答案
s=’Aatb32_67mnq’
count=0
flag1,flag2,flag3,flag4=True,True,True,True
for i in s:
????if i in ‘0123456789’:
????????if flag1:
????????????count+=1
????????flag1=False
????if i in ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’:
????????if flag2:
????????????count+=1
????????flag2=False
????if i in ‘abcdefghijklmnopqrstuvwxyz’:
????????if flag3:
????????????count+=1
? ? ? ? flag3=False
????if i in ‘_’:
????????if flag4:
????????????count+=1
????????flag4=False
if count==4:
????print(“it’s a right passwd”)
else:
????print(‘passwd is wrong’)
3.日志統計
狀態200的不同jsp頁面訪問次數
統計不同類型文件的訪問次數,文件類型有靜態類(js、css)、圖片類(jpg、jpeg、gif、png)、動態類(action、jsp、do)
日志如下:
116.226.208.136 – – [28/Apr/2015:09:01:38 +0800] “GET /js/check.js HTTP/1.1” 304 –
59.53.22.67 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery.datepick.css HTTP/1.1” 304 –
117.93.56.165 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery-1.4.2.js HTTP/1.1” 304 –
106.39.189.200 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery.datepick.js HTTP/1.1” 304 –
219.146.71.17 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery.datepick-zh-CN.js HTTP/1.1” 304 –
111.11.83.162 – – [28/Apr/2015:09:01:38 +0800] “GET /images/shim.gif HTTP/1.1” 304 –
117.93.56.165 – – [28/Apr/2015:09:01:38 +0800] “GET /images/button_ok.gif HTTP/1.1” 304 –
111.206.221.200 – – [28/Apr/2015:09:01:38 +0800] “GET /images/button_cancel.gif HTTP/1.1” 304 –
112.80.144.85 – – [28/Apr/2015:09:01:46 +0800] “GET /user/list.jsp HTTP/1.1” 200 7644
117.148.200.56 – – [28/Apr/2015:09:01:46 +0800] “GET /images/i_edit.gif HTTP/1.1” 304 –
183.12.49.80 – – [28/Apr/2015:09:01:46 +0800] “GET /images/i_del.gif HTTP/1.1” 304 –
175.19.57.147 – – [28/Apr/2015:09:01:46 +0800] “GET /images/button_view.gif HTTP/1.1” 304 –
117.136.63.218 – – [28/Apr/2015:09:05:46 +0800] “GET /user/list.jsp HTTP/1.1” 200 7644
157.55.39.102 – – [28/Apr/2015:09:05:56 +0800] “GET /login.jsp HTTP/1.1” 200 2607
111.206.221.68 – – [28/Apr/2015:09:05:58 +0800] “POST /user_login.action HTTP/1.1” 200 2809
117.93.56.165 – – [28/Apr/2015:09:06:12 +0800] “POST /user_login.action HTTP/1.1” 302 –
223.98.218.205 – – [28/Apr/2015:09:06:12 +0800] “GET /login/home.jsp HTTP/1.1” 200 743
117.136.97.78 – – [28/Apr/2015:09:06:12 +0800] “GET /login/welcome.jsp HTTP/1.1” 200 1142
111.206.221.68 – – [28/Apr/2015:09:06:12 +0800] “GET /login.jsp HTTP/1.1” 200 803
117.93.56.165 – – [28/Apr/2015:09:06:12 +0800] “GET /login/top.jsp HTTP/1.1” 200 2052
111.206.221.68 – – [28/Apr/2015:09:06:13 +0800] “GET /login.jsp HTTP/1.1” 200 1113
4.打印矩陣外圈
?1 ? ? ?2 ? ? ?6 ? ? ? 7
?3 ? ? ?5 ? ? ?8 ? ? ?13
?4 ? ? ?9 ? ? 12 ? ? 14
10 ? ?11 ? ?15 ? ? 16
打印順序為1,2,6,7,13,14,16,15,11,10,4,3
5.打印矩陣元素
?1 ? ? ?2 ? ? ?6 ? ? ? 7
?3 ? ? ?5 ? ? ?8 ? ? ?13
?4 ? ? ?9 ? ? 12 ? ? 14
10 ? ?11 ? ?15 ? ? 16
之字形打印結果為1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
第三題的答案
lst=[‘116.226.208.136 – – [28/Apr/2015:09:01:38 +0800] “GET /js/check.js HTTP/1.1” 304 -‘
,’59.53.22.67 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery.datepick.css HTTP/1.1” 304 -‘
,’117.93.56.165 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery-1.4.2.js HTTP/1.1” 304 -‘
,’106.39.189.200 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery.datepick.js HTTP/1.1” 304 -‘
,’219.146.71.17 – – [28/Apr/2015:09:01:38 +0800] “GET /jquery/jquery.datepick-zh-CN.js HTTP/1.1” 304 -‘
,’111.11.83.162 – – [28/Apr/2015:09:01:38 +0800] “GET /images/shim.gif HTTP/1.1” 304 -‘
,’117.93.56.165 – – [28/Apr/2015:09:01:38 +0800] “GET /images/button_ok.gif HTTP/1.1” 304 -‘
,’111.206.221.200 – – [28/Apr/2015:09:01:38 +0800] “GET /images/button_cancel.gif HTTP/1.1” 304 -‘
,’112.80.144.85 – – [28/Apr/2015:09:01:46 +0800] “GET /user/list.jsp HTTP/1.1” 200 7644′
,’117.148.200.56 – – [28/Apr/2015:09:01:46 +0800] “GET /images/i_edit.gif HTTP/1.1” 304 -‘
,’183.12.49.80 – – [28/Apr/2015:09:01:46 +0800] “GET /images/i_del.gif HTTP/1.1” 304 -‘
,’175.19.57.147 – – [28/Apr/2015:09:01:46 +0800] “GET /images/button_view.gif HTTP/1.1” 304 -‘
,’117.136.63.218 – – [28/Apr/2015:09:05:46 +0800] “GET /user/list.jsp HTTP/1.1” 200 7644′
,’157.55.39.102 – – [28/Apr/2015:09:05:56 +0800] “GET /login.jsp HTTP/1.1” 200 2607′
,’111.206.221.68 – – [28/Apr/2015:09:05:58 +0800] “POST /user_login.action HTTP/1.1” 200 2809′
,’117.93.56.165 – – [28/Apr/2015:09:06:12 +0800] “POST /user_login.action HTTP/1.1” 302 -‘
,’223.98.218.205 – – [28/Apr/2015:09:06:12 +0800] “GET /login/home.jsp HTTP/1.1” 200 743′
,’117.136.97.78 – – [28/Apr/2015:09:06:12 +0800] “GET /login/welcome.jsp HTTP/1.1” 200 1142′
,’111.206.221.68 – – [28/Apr/2015:09:06:12 +0800] “GET /login.jsp HTTP/1.1” 200 803′
,’117.93.56.165 – – [28/Apr/2015:09:06:12 +0800] “GET /login/top.jsp HTTP/1.1” 200 2052′
,’111.206.221.68 – – [28/Apr/2015:09:06:13 +0800] “GET /login.jsp HTTP/1.1” 200 1113′]
length=len(lst)
namelist=[]
for i in range(length):
????*_,name,_,_,_=lst[i].split()
????namelist.append(name)
lst3=[]
for i in range(length):
????lst4=namelist[i].split(‘.’)
????lst3.append(lst4[-1])
lst3.sort()
count=1
for i in range(length-1,-1,-1):
????if lst3[i]==lst3[i-1]:
????????count+=1
????else:
????????print(lst3[i]+str(count))
????????count=1
運行效果:
jsp8
js4
gif6
css1
action2
第四題的答案
lst =[[1,2,6,7],[3,5,8,13],[4,9,12,14],[10,11,15,16]]
newlst=[]
for i in range(len(lst)):
????if i ==0:
????????for j in range(len(lst[i])):
????????????newlst.append(lst[i][j])
????if i>0 and i<(len(lst)-1):
????????newlst.append(lst[i][len(lst[i])-1])
????if i==(len(lst)-1):
????????for k in range(len(lst[i])):
????????????newlst.append(lst[i][len(lst[i])-k-1])
for i in range((len(lst)-1),0,-1):
????newlst.append(lst[i][0])
print(newlst)
第五題的答案
lst=[[1,2,6,7],[3,5,8,13],[4,9,12,14],[10,11,15,16]]
flag=True
for i in range(-3,4):
????if i<0:
????????if flag:
????????????for j in range(4+i):
????????????????print(lst[3+i-j][j])
????????????flag=False
????????else:
????????????for j in range(4+i):
????????????????print(lst[j][3+i-j])
????????????flag=True
????elif i>0:
????????if flag:
????????????for j in range(4-i):
????????????????print(lst[j+i][3-j])
????????????flag=False
????????else:
????????????for j in range(4-i):
????????????????print(lst[3-j][j+i])
????????????flag=True
????else:
????????for j in range(4):
????????????print(lst[j][3-j])

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.npownk.tw/87618

聯系我們

400-080-6560

在線咨詢

工作時間:周一至周五,9:30-18:30,節假日同時也值班

QR code
安徽十一选五分布走势