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
7190ed6a
authored
Apr 05, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
2ffe1ce6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
17 deletions
bbbb.py
test1.py
test2.py
bbbb.py
View file @
7190ed6a
a
=
3
b
=
2
a
,
b
=
b
,
a
print
(
a
,
b
)
\ No newline at end of file
a
=
3
b
=
2
# a,b = b,a
# print(a,b)
c
=
0
c
=
a
#3
a
=
b
#2
b
=
c
#3
print
(
a
,
b
)
test1.py
View file @
7190ed6a
#输入n个正整数将其存储到一个列表中,然后从小到大升序排列
#第一步存储
#第一步
:
存储
num_list
=
[]
n
=
int
(
input
(
"请输入数字个数:"
))
n
=
int
(
input
(
"请输入
需要的
数字个数:"
))
for
i
in
range
(
n
):
num
=
int
(
input
(
"
请输入"
+
str
(
i
+
1
)
+
"个数字:
"
))
num
=
int
(
input
(
"
输入第"
+
str
(
i
+
1
)
+
"个数字
"
))
num_list
.
append
(
num
)
print
(
num_list
)
#第二步:从小到大冒泡排序
#表示第几轮
#第二步:冒泡排序
for
i
in
range
(
n
-
1
):
#表示索引位置
for
j
in
range
(
n
-
1
-
i
):
for
j
in
range
(
n
-
1
):
if
num_list
[
j
]
>
num_list
[
j
+
1
]:
num_list
[
j
],
num_list
[
j
+
1
]
=
num_list
[
j
+
1
],
num_list
[
j
]
print
(
num_list
)
...
...
@@ -27,3 +25,10 @@ for i in range(n-1):
test2.py
View file @
7190ed6a
...
...
@@ -15,16 +15,17 @@
#冒泡排序的实现原理
def
maopao
(
list
):
n
=
len
(
list
)
#i表示
当前
第几轮
#i表示第几轮
for
i
in
range
(
n
-
1
):
#j表示
列表
的下标
for
j
in
range
(
n
-
1
-
i
):
#j表示
索引位置对应
的下标
for
j
in
range
(
n
-
1
):
#比大小
if
list
[
j
]
>
list
[
j
+
1
]:
#换位置
#
交
换位置
list
[
j
],
list
[
j
+
1
]
=
list
[
j
+
1
],
list
[
j
]
...
...
@@ -37,3 +38,7 @@ def maopao(list):
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