Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-5-1
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
76120996
authored
Jun 15, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
0db28b07
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
5 deletions
diy.py
diy.py
View file @
76120996
# 臂力挑战赛
# 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name
=
'刘强'
power
=
66
hero
=
[
'赵一'
,
30
,
'丁二'
,
37
,
'孙五'
,
52
,
'王猛'
,
89
,
'周亮'
,
98
]
hero
=
[
'赵一'
,
30
,
'丁二'
,
37
,
'孙五'
,
52
,
'王猛'
,
89
,
'周亮'
,
98
]
# 自动排序
# 自动排序
name
=
input
(
'姓名:'
)
#NI JIA YOU倪嘉佑 PU SI QUAN蒲思泉
#因为input函数会强制把输入的内容转换为字符串类型,
#因此需要先转换为整型才能进行数学运算
power
=
int
(
input
(
'臂力值:'
))
for
i
in
range
(
len
(
hero
)):
for
i
in
range
(
len
(
hero
)):
# 如果臂力值小于或等于列表中的某一项,就插入到这一项的前面
if
i
%
2
==
1
and
hero
[
i
]
>=
power
:
if
i
%
2
==
1
and
hero
[
i
]
>=
power
:
hero
.
insert
(
i
-
1
,
name
)
hero
.
insert
(
i
-
1
,
name
)
hero
.
insert
(
i
,
power
)
hero
.
insert
(
i
,
power
)
print
(
hero
)
break
# 跳出整个循环
\ No newline at end of file
# 如果臂力值大于列表中的某一项,就插入到这一项的后面
if
hero
[
len
(
hero
)
-
1
]
<
power
:
hero
.
append
(
name
)
hero
.
append
(
power
)
break
print
(
hero
)
# 统计出臂力值排名前三
print
(
hero
[
-
6
:])
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