From 36d517efa3896c5713b62c1d35d912d74b080dd5 Mon Sep 17 00:00:00 2001 From: chkliao <5991706775@qq.com> Date: Mon, 14 Oct 2019 11:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=98=E5=BB=96=E8=AF=9A=E5=87=AF=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...- \345\273\226\350\257\232\345\207\257.md" | 226 ++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 "python-interview-2019-3 - \345\273\226\350\257\232\345\207\257.md" diff --git "a/python-interview-2019-3 - \345\273\226\350\257\232\345\207\257.md" "b/python-interview-2019-3 - \345\273\226\350\257\232\345\207\257.md" new file mode 100644 index 0000000..51f7d09 --- /dev/null +++ "b/python-interview-2019-3 - \345\273\226\350\257\232\345\207\257.md" @@ -0,0 +1,226 @@ +### Python开发工程师笔试题3 + +> **答题要求**:将该项目从[地址1]()或[地址2]()**fork**到自己的[GitHub]()或[Gitee](https://gitee.com)仓库并在线填写答案,完成后以发送合并请求(**Pull Request**)的方式提交自己的工作成果,时间120分钟。 + +#### 答题人: + +#### 题目: + +1. 下面的Python代码会输出什么。 + + ```Python + print([(x, y) for x, y in zip('abcd', (1, 2, 3, 4, 5))]) + print({x: f'item{x ** 2}' for x in range(5) if x % 2}) + print(len({x for x in 'hello world' if x not in 'abcdefg'})) + ``` + + 答案: + + ``` + 1)报错,IndexEorrer + 2){x: 'item0', x: 'item4', x:'item16'} + 3)2 + ``` + +2. 下面的Python代码会输出什么。 + + ```Python + from functools import reduce + + items = [11, 12, 13, 14] + print(reduce(int.__add__, map(lambda x: x // 2, filter(lambda x: x ** 2 > 150, items)))) + ``` + + 答案: + + ``` + 13 + ``` + +3. 对于第2题的代码,如果要实现相同的功能,用生成式应该怎么写? + + 答案: + + ```Python + sum([x for x in items if x ** 2 > 150]) + ``` + +4. 用一行代码实现将字符串`k1:v1|k2:v2|k3:v3`处理成字典`{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}`。 + + 答案: + + ```Python + {(x.split(':')[0], x.split(':')[1]) for x in str1.split('|')} + ``` + +5. 写一个装饰函数的装饰器,实现如果函数的返回值是字符串类型,就将该字符串每个单词的首字母大写(不用考虑非英文字符串的情况)。 + + 答案: + + ```Python + def a(f): + if isinstence(f,str): + def b(*args,**kwargs): + return 'x'.join([x.upper() for x in f(*args,**kwargs).split(' ')]) + return b + ``` + +6. 下面的字典中保存了某些公司股票的代码(字典中的键)及价格(字典中的值,以美元为单位),用一行代码从中找出价格最高的股票对应的股票代码,再用一行代码将股价高于100美元的股票创建成一个新的字典。 + + > 说明:美股的股票代码是指英文字母代码,如:AAPL、GOOG。 + + ```Python + prices = { + 'AAPL': 191.88, + 'GOOG': 1186.96, + 'IBM': 149.24, + 'ORCL': 48.44, + 'ACN': 166.89, + 'FB': 208.09, + 'SYMC': 21.29 + } + ``` + + 答案: + + ```Python + 1)[x for x in prices if prices[x] == max[v for k,v in prices.items()]] + 2){k,v for k,v in prices.items() if v > 100} + + ``` + +7. 写一个函数,返回删除列表中重复元素后的新列表,要求保留原有列表元素的顺序。 + + 答案: + + ```Python + new_list = [] + for x in list1: + if x not in new_list: + new_list.append(x) + ``` + +8. 写一个函数,该函数的参数是一个保存字符串的列表,列表中某个字符串出现次数占列表元素总数的半数以上,找出并返回这个字符串。 + + 答案: + + ```Python + def f(list_str:list): + dict1 = {} + for x in list_str: + if x in dict1: + dict1[x] += 1 + else: + dict1[x] = 0 + for x in dict1: + if dict1[x] > len(list_str) // 2: + return x + + + ``` + +9. MySQL关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。 + + 用户表(`tb_user`): + + ``` + +----------+-------------+------+-----+---------+----------------+ + | Field | Type | Null | Key | Default | Comment | + +----------+-------------+------+-----+---------+----------------+ + | userid | int(11) | NO | PRI | NULL | 用户编号 | + | username | varchar(31) | NO | | NULL | 用户姓名 | + | usertel | char(11) | YES | | NULL | 用户手机 | + +----------+-------------+------+-----+---------+----------------+ + ``` + + 房源表(`tb_house`) + + ``` + +---------+--------------+------+-----+---------+----------------+ + | Field | Type | Null | Key | Default | Comment | + +---------+--------------+------+-----+---------+----------------+ + | houseid | int(11) | NO | PRI | NULL | 房源编号 | + | title | varchar(255) | NO | | NULL | 房源标题 | + | area | decimal(5,1) | NO | | NULL | 房源面积 | + | addr | varchar(511) | NO | | NULL | 房源地址 | + | rented | tinyint(1) | YES | | 0 | 是否租出 | + +---------+--------------+------+-----+---------+----------------+ + ``` + + 租房记录表(`tb_record`) + + ``` + +---------+---------+------+-----+---------+----------------+ + | Field | Type | Null | Key | Default | Comment | + +---------+---------+------+-----+---------+----------------+ + | recid | int(11) | NO | PRI | NULL | 记录编号 | + | userid | int(11) | NO | MUL | NULL | 用户编号 | + | houseid | int(11) | NO | MUL | NULL | 房源编号 | + | indate | date | NO | | NULL | 租赁日期 | + | outdate | date | YES | | NULL | 退租日期 | + +---------+---------+------+-----+---------+----------------+ + ``` + + - 查询租过编号为1055的房源的用户姓名。 + - 查询租过三套以上房子且登记了手机号码的用户姓名。 + - 查询2018年被租过两次以上目前仍然处于出租状态且面积超过50平米的房源编号和标题。 + + 答案: + + ```SQL + 1) + select username from tb_user , + (select userid from tb_record where tb_record.houseid == 1055) as t1 + where tb_user.userid = t1.userid; + 2) + select username from tb_user, + (select userid, count(houseid) from tb_record group by(userid) having count(houseid) > 3) as t1 + where tb_user.userid == t1.userid; + 3) + select tb_house.houseid, title from tb_house, + (select tb_record.houseid,count(recid) from tb_record + where (indate >= '2018-01-01'and indate <= '2018-12-31') + group by tb_record.houseid + having and count(recid) > 2) as t1 + where tb_house.houseid == t1.houseid and area > 50 and rented == 1; + + ``` + +10. 请阐述访问一个用Django或Flask开发的Web应用,从用户在浏览器中输入网址回车到浏览器收到Web页面的整个过程中,到底发生了哪些事情,越详细越好。 + + 答案: + + ``` + 首先 浏览器会通过网址路由发送一个request请求给后端, + 后端收到后,会解析网址路由,解析后交给相应的视图文件对具体的请求内容在做操作, + 视图文件会在request中找到需要的数据,以及想要的结果,并加以处理, + 然后将最后的结果通过response返回给页面 + 这样浏览器收到后端返回的response后就可以将其中需要的信息拿出来加以渲染,呈现出来 + ``` + +11. 请阐述HTTPS的工作原理以及TCP是如何保证端到端可靠传输的。 + + 答案: + + ``` + HTTPS,相较于HTTP而言,多了个安全加密的SSL层 + ``` + +12. 在Linux系统中,假设Nginx的访问日志位于`/var/log/nginx/access.log`,该文件的每一行代表一条访问记录,每一行都由若干列(以制表键分隔)构成,其中第1列记录了访问者的IP地址,如下所示。请用一行命令找出最近的100000次访问中,访问频率最高的IP地址及访问次数。 + + ``` + 221.228.143.52 - - [23/May/2019:08:57:42 +0800] ""GET /about.html HTTP/1.1"" 206 719996 + 218.79.251.215 - - [23/May/2019:08:57:44 +0800] ""GET /index.html HTTP/1.1"" 206 2350253 + 220.178.150.3 - - [23/May/2019:08:57:45 +0800] ""GET /index.html HTTP/1.1"" 200 2350253 + 218.79.251.215 - - [23/May/2019:08:57:52 +0800] ""GET /index.html HTTP/1.1"" 200 2350253 + 219.140.190.130 - - [23/May/2019:08:57:59 +0800] ""GET /index.html HTTP/1.1"" 200 2350253 + 221.228.143.52 - - [23/May/2019:08:58:08 +0800] ""GET /about.html HTTP/1.1"" 206 719996 + 221.228.143.52 - - [23/May/2019:08:58:08 +0800] ""GET /news.html HTTP/1.1"" 206 713242 + 221.228.143.52 - - [23/May/2019:08:58:09 +0800] ""GET /products.html HTTP/1.1"" 206 1200250 + ``` + + 答案: + + ```Shell + cat /var/log/nginx/access.log -ls | count() | limit 1 + ``` \ No newline at end of file -- Gitee