Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson13-diy1
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
2ffe1ce6
authored
Apr 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
aa3f81d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
14 deletions
bbbb.py
test1.py
test2.py
bbbb.py
0 → 100644
View file @
2ffe1ce6
a
=
3
b
=
2
a
,
b
=
b
,
a
print
(
a
,
b
)
\ No newline at end of file
test1.py
View file @
2ffe1ce6
#输入n个正整数将其存储到一个列表中,然后从小到大升序排列
#输入n个正整数将其存储到一个列表中,然后从小到大升序排列
#第一步
:
存储
#第一步存储
num_list
=
[]
num_list
=
[]
n
=
int
(
input
(
"请输入
需要的
数字个数:"
))
n
=
int
(
input
(
"请输入数字个数:"
))
for
i
in
range
(
n
):
for
i
in
range
(
n
):
num
=
int
(
input
(
"
输入的第"
+
str
(
i
+
1
)
+
"个数
"
))
num
=
int
(
input
(
"
请输入"
+
str
(
i
+
1
)
+
"个数字:
"
))
num_list
.
append
(
num
)
num_list
.
append
(
num
)
print
(
num_list
)
#第二步:从小到大冒泡排序
#表示第几轮
#冒泡排序:从小到大
for
i
in
range
(
n
-
1
):
for
i
in
range
(
n
-
1
):
#表示索引位置
for
j
in
range
(
n
-
1
-
i
):
for
j
in
range
(
n
-
1
-
i
):
if
num_list
[
j
]
>
num_list
[
j
+
1
]:
if
num_list
[
j
]
>
num_list
[
j
+
1
]:
num_list
[
j
],
num_list
[
j
+
1
]
=
num_list
[
j
+
1
],
num_list
[
j
]
num_list
[
j
],
num_list
[
j
+
1
]
=
num_list
[
j
+
1
],
num_list
[
j
]
print
(
num_list
)
print
(
num_list
)
...
@@ -20,3 +21,9 @@ for i in range(n-1):
...
@@ -20,3 +21,9 @@ for i in range(n-1):
test2.py
View file @
2ffe1ce6
#从小到大
[
5
,
8
,
6
,
3
,
9
,
2
,
1
,
7
]
[
5
,
8
,
6
,
3
,
9
,
2
,
1
,
7
]
#第一轮
#第一轮
[
5
,
6
,
3
,
8
,
2
,
1
,
7
,
9
]
[
5
,
6
,
3
,
8
,
2
,
1
,
7
,
9
]
...
@@ -12,16 +13,24 @@
...
@@ -12,16 +13,24 @@
#第六轮
#第六轮
[
1
,
2
,
3
,
5
,
6
,
7
,
8
,
9
]
[
1
,
2
,
3
,
5
,
6
,
7
,
8
,
9
]
#冒泡排序的实现原理
#冒泡排序的实现原理
def
b_l
(
l
):
def
maopao
(
list
):
n
=
len
(
l
)
n
=
len
(
l
ist
)
#i表示第几轮
#i表示
当前
第几轮
for
i
in
range
(
0
,
n
-
1
):
for
i
in
range
(
n
-
1
):
#j表示列表的下标
#j表示列表的下标
for
j
in
range
(
0
,
n
-
1
-
i
):
for
j
in
range
(
n
-
1
-
i
):
#比大小
#比大小
if
l
[
j
]
>
l
[
j
+
1
]:
if
list
[
j
]
>
list
[
j
+
1
]:
l
[
j
],
l
[
j
+
1
]
=
l
[
j
+
1
],
l
[
j
]
#换位置
list
[
j
],
list
[
j
+
1
]
=
list
[
j
+
1
],
list
[
j
]
...
...
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