用python玩转数据-实验5

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验3数据获取和表示

Deadline:5月2日20:00

编程题

1.列表统计(可利用ord等函数)字符串中所有出现的字母的个数(不区分大小写)。例如对于字符串“Hello, World!”,统计结果为:

[0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 3, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0]

2.有5名某界大佬xiaoyun、xiaohong、xiaoteng、xiaoyi和xiaoyang,其QQ号分别是88888、5555555、11111、1234321和1212121,用字典将这些数据组织起来。编程实现以下两个功能:

(1)用户输入某一个大佬的姓名后可以输出其QQ号,如果输入的姓名不在字典中则返回提示信息并允许再次输入;

(2)寻找所有有QQ靓号(5位数或小于5位数)的大佬,输出所有姓名。

其中提示输入和输出结果的两句提示语请使用如下形式:

name = input("Please input the name:")

print("Who has the nice QQ number?")

3.创建一个文件Blowing in the wind.txt,其内容是:

How many roads must a man walk down

Before they call him a man

How many seas must a white dove sail

Before she sleeps in the sand

How many times must the cannon balls fly

Before they're forever banned

The answer my friend is blowing in the wind

The answer is blowing in the wind

(1)在文件头部插入歌名“Blowin’ in the wind”

(2)歌名后插入歌手名“Bob Dylan”

(3)在文件末尾加上字符串“1962 by Warner Bros. Inc.”

(4)在屏幕上打印文件内容

文件处理后的内容为:

Blowin’ in the wind

Bob Dylan

How many roads must a man walk down

Before they call him a man

How many seas must a white dove sail

Before she sleeps in the sand

How many times must the cannon balls fly

Before they're forever banned

The answer my friend is blowing in the wind

The answer is blowing in the wind

1962 by Warner Bros. Inc.

注意:加入内容都是加入新行,所以优先考虑用insert函数

4.利用requests库中的方法抓取百度贴吧(贴吧的搜索引擎的查询接口是

/p/)中的若干网页(pages_list)并保存到本地硬盘中,程序框架如下所示:

import requests

def baidu_tieba(url, pages_list):

if __name__ == "__main__":

url = "/p/"

pages_list = [4779995461,4781463980,4826066853,4560596856,4819859278]

baidu_tieba(url, pages_list)

相关文档
最新文档