几个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

(2)
daishitongdaishitong
上一篇 2017-10-02
下一篇 2017-10-03

相关推荐

  • 博客启动计划&我个人理解的Python优缺点

    很久没有写博客了,因为最近一直在使用Python。Python实在不是一门好的工作用语言(我的观点是所有的动态语言都不是好的工作用语言,不仅是Python),但是自己玩还是可以的。但,生活所迫,还是要继续用的呀(笑)。 所以呢,博客还是要写的,java还是最喜欢的,Python也是要学习的,当然其实更多是总结了。既然博客要启动了,这篇文字就权当测试吧,使用公…

    Linux干货 2015-03-13
  • 基于Python和MoviePy库实现数据的动态展示

    基于Python和MoviePy库实现数据的动态展示 (翻译:以马内利)  原文链接:Data Animations With Python and MoviePy   Python拥有很多实现数据可视化的库,但是很少可以展示GIFs的动态视图。 这篇博客主要介绍怎样使用MoviePy库作为一个其他可视化库的通用插件。 Movi…

    2015-03-26
  • Python高阶函数及装饰器

    First Class Object 函数在Python中是一等公民 函数也是对象,可调用的对象 函数可作为普通变量、参数、返回值等 高阶函数 数学定义:y=g(f(x)) 高阶函数需满足的条件,至少其一 接受一个或多个函数作为参数 输出一个函数 内建函数的高阶函数 排序:sorted(iterable[,key][,reverse]) 返回一个新列表,对一…

    2018-04-22
  • python基础语法之if,else,for,while,continue,break

    如果你了解语法的使用,内有习题可以稍作练习。

    2017-09-16
  • Python内置数据结构

    解析器和生成器

    Python笔记 2018-04-08
  • 二叉树的遍历和堆排序

    二叉树的遍历和堆排序

    Python笔记 2018-05-16