Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦想橡皮擦
python 题库
提交
d7fe9a50
P
python 题库
项目概览
梦想橡皮擦
/
python 题库
通知
50
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
python 题库
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d7fe9a50
编写于
10月 13, 2021
作者:
梦想橡皮擦
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
模块 random
上级
df7373ba
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
86 addition
and
1 deletion
+86
-1
README.md
README.md
+9
-1
常用标准库/题目1.py
常用标准库/题目1.py
+12
-0
常用标准库/题目2.py
常用标准库/题目2.py
+15
-0
常用标准库/题目3.py
常用标准库/题目3.py
+23
-0
常用标准库/题目4.py
常用标准库/题目4.py
+10
-0
常用标准库/题目5.py
常用标准库/题目5.py
+17
-0
未找到文件。
README.md
浏览文件 @
d7fe9a50
# python 题库
# python 题库
主要用于 python 基础知识点题库备份
主要用于 python 基础知识点题库备份.
\ No newline at end of file
相关博客
-
[
python 入门教程之每日 5 or 6 道题,列表推导式篇 | Python技能树征题
](
https://dream.blog.csdn.net/article/details/120476685
)
-
[
三元表达式篇,python 入门教程之每日 5 or 6 道题 | Python技能树征题
](
https://dream.blog.csdn.net/article/details/120498213
)
-
[
断言、with-as 篇,python 入门教程之每日 5 or 6 道题 | Python 技能树题库
](
https://dream.blog.csdn.net/article/details/120553317
)
-
[
常用标准库 random,python 入门教程之每日 5 or 6 道题 | Python 技能树题库
](
https://dream.blog.csdn.net/article/details/120743071
)
常用标准库/题目1.py
0 → 100644
浏览文件 @
d7fe9a50
"""
题干(问题描述):
下述哪个选项能在 1~100 中的随机选择 10 个数字
"""
import
random
for
i
in
range
(
1
,
6
):
rand_num
=
random
.
randint
(
1
,
100
)
print
(
rand_num
)
常用标准库/题目2.py
0 → 100644
浏览文件 @
d7fe9a50
"""
题干(问题描述):
编写程序,在程序中随机为用户生成 6 位数短信验证码,包含大写字母。
"""
import
random
password
=
[]
for
i
in
range
(
3
):
num
=
random
.
randint
(
0
,
9
)
password
.
append
(
str
(
num
))
char_num
=
random
.
randint
(
65
,
90
)
password
.
append
(
chr
(
char_num
))
print
(
""
.
join
(
password
))
常用标准库/题目3.py
0 → 100644
浏览文件 @
d7fe9a50
"""
题干(问题描述):
爬虫代码编写中,会随机获取用户代理值,即 User-Agent,编写函数,实现随机从列表中获取 User-Agent。
"""
import
random
def
get_headers
():
uas
=
[
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
,
"Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)"
,
"Baiduspider-image+(+http://www.baidu.com/search/spider.htm)"
,
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36"
,
]
ua
=
random
.
choice
(
uas
)
headers
=
{
"user-agent"
:
ua
}
return
headers
if
__name__
==
'__main__'
:
print
(
get_headers
())
常用标准库/题目4.py
0 → 100644
浏览文件 @
d7fe9a50
"""
题干(问题描述):
在 1000 内,随机获取 6 个整数,要求各个数字互不重复。
"""
from
random
import
sample
ret
=
sample
(
range
(
1000
),
6
)
print
(
ret
)
常用标准库/题目5.py
0 → 100644
浏览文件 @
d7fe9a50
"""
题干(问题描述):
随机生成一个由 1 和 0 组成的列表(长度要求为 20),其中 0 的个数不能超过 5 个。
"""
import
random
zero_max
=
5
my_list
=
[
1
]
*
20
zero_list
=
random
.
randint
(
0
,
zero_max
)
zero_pos
=
random
.
sample
(
range
(
20
),
zero_list
)
for
pos
in
zero_pos
:
my_list
[
pos
]
=
0
print
(
my_list
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录