几个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.178linux.com/87618

发表评论

电子邮件地址不会被公开。 必填项已用*标注

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1660809109@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班