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
ab2d4b0b
authored
Jul 01, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
4448ff54
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
5 deletions
demo1.py
diy.py
diy1.py
demo1.py
0 → 100644
View file @
ab2d4b0b
'''
bros=["刘备","关羽","张飞"]
#进行1,2位置交换 一:
bros[0]="关羽"
bros[1]="刘备"
#进行1,2位置交换 二:
bros[0],bros[1]="关羽","刘备"
#进行1,2位置交换 三:
bros[0],bros[1]=bros[1],bros[0]
print(bros)
list=["袁术","刘备","关羽","张飞","曹操"]
list1=["华雄"]
list.remove("关羽")
print(list)
#通过索引插入
#list1.insert(1,"关羽")
#添加到列表末尾
list1.append("关羽")
c=["颜良","文丑"]
#在末尾添加一个列表
list1.extend(c)
print(list1)
'''
list
=
[
"袁术"
,
"刘备"
,
"关羽"
,
"张飞"
,
"曹操"
]
a
=
[
"吕布"
]
#切片 列表名[索引:索引+1]
print
(
list
[
1
:
4
])
a
.
extend
(
list
[
1
:
4
])
print
(
a
)
\ No newline at end of file
diy.py
View file @
ab2d4b0b
# 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name
=
'刘强'
power
=
40
name
=
input
(
"请输入您的名字:"
)
power
=
int
(
input
(
"请输入您的臂力值:"
))
hero
=
[
'赵一'
,
30
,
'丁二'
,
37
,
'孙五'
,
52
,
'王猛'
,
89
,
'周亮'
,
98
]
# 自动排序
print
(
hero
)
\ No newline at end of file
for
i
in
range
(
1
,
len
(
hero
),
2
):
if
power
<=
hero
[
i
]:
hero
.
insert
(
i
-
1
,
power
)
hero
.
insert
(
i
-
1
,
name
)
break
#跳出循环
print
(
hero
)
print
(
hero
[
-
6
:])
\ No newline at end of file
diy1.py
0 → 100644
View file @
ab2d4b0b
# 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name
=
'刘强'
power
=
int
(
input
(
"请输入臂力值:"
))
hero
=
[
'赵一'
,
30
,
'丁二'
,
37
,
'孙五'
,
52
,
'王猛'
,
89
,
'周亮'
,
98
]
# 自动排序
for
i
in
range
(
1
,
len
(
hero
),
2
):
if
power
<=
hero
[
i
]:
hero
.
insert
(
i
-
1
,
power
)
hero
.
insert
(
i
-
1
,
name
)
break
if
power
>
hero
[
len
(
hero
)
-
1
]:
hero
.
append
(
name
)
hero
.
append
(
power
)
print
(
hero
)
\ 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