Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson10-2
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
212ca8f1
authored
Sep 07, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
3dfc4cb4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
24 deletions
diy1.py
quiz.py
diy1.py
View file @
212ca8f1
# 灭霸打了一个响指,宇宙一半生物都灰飞烟灭。
'''
# 剩下的复仇者联盟成员们依旧没有放弃反击灭霸的机会,他们决定利用最后一次行动机会,去把灭霸手里的宝石偷回来。
map( , ) 用于对列表中每个元素执行相同的任务,
# 如果偷回的宝石数是4颗及以上,便获得了打败灭霸的力量;如果偷回的宝石数是1-3颗,他们可以全员出动,殊死一搏;如果偷回的宝石数是0颗,只能尝试呼叫惊奇队长。
是可迭代对象,需要通过list转换为列表
# 最终,他们因为实力相差太大,1颗宝石都没有偷回来。
函数/方法 可迭代对象
# 悟空读了上面的故事,写出一段代码,在一颗宝石都没偷回来的赋值下,进行条件判断,并产生对应的结果:
# 如果偷回的宝石数是4颗及以上,输出结果:获得了打败灭霸的力量,反杀稳了
# 如果偷回的宝石数是1-3颗,输出结果:可以全员出动,殊死一搏
# 如果偷回的宝石数是0颗,输出结果:没办法了,只能尝试呼叫惊奇队长
# 但是运行错误了,请你帮助悟空消灭bug!
if
stonenumber
>=
4
:
def f(x):
print
(
'获得了打败灭霸的力量,反杀稳了'
)
a=x*x
elif
1
<=
stonenum
<=
3
:
return a
print
(
'可以全员出动,殊死一搏'
)
print(list(map(f,[1,2,3,4])))
else
:
print
(
'没办法了,只能尝试呼叫惊奇队长'
)
print(eval('6+5')) #class int
print(repr(6+5)) #class str
#all() 用于判定可迭代对象中的每一个元素的逻辑值是否都为True,
#如果是则返回True,否则返回False
print(all([5,-1,True]))
find( , , ) 用于字符串的查找操作
要搜索的 开始 结尾
子字符串 (0) (字符串的长度)
返回子字符串的第一个索引值
'''
random
.
randint
(
1
,
10
)
\ No newline at end of file
quiz.py
View file @
212ca8f1
# 勇于挑战的创造师,下面的代码犯了三类典型错误,请你把bug揪出来吧。
a
=
'3,5,6,34,2'
score
=
{
'悟空语文'
:
95
,
'悟空数学'
:
88
,
'悟空英语'
:
85
,
'悟空美术'
:
97
}
print
(
a
.
split
(
','
))
# 打印出悟空语文成绩
\ No newline at end of file
print
(
sore
[
'悟空语文'
])
# 打印出悟空的美术成绩
print
(
score
[
97
])
# 打印出悟空英语成绩:
print
(
'悟空英语成绩是'
+
score
[
'悟空英语'
]
+
'分!'
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment