Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson13-diy2
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
95038bc6
authored
Mar 26, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
0a7b0048
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
0 deletions
diy.py
diy1.py
diy2.py
diy3.py
diy.py
0 → 100644
View file @
95038bc6
#自己输入n个整数,然后进行从大到小排序
list
=
[]
#input输入的是字符串类型
n
=
int
(
input
(
'输入排序元素的个数:'
))
for
i
in
range
(
n
):
list
.
append
(
int
(
input
(
'输入一个整数,按回车继续:'
)))
print
(
'排序前的列表:'
,
list
)
diy1.py
0 → 100644
View file @
95038bc6
#time模块
#time.time()
#返回一个时间戳,秒数
import
time
start_time
=
time
.
time
()
for
a
in
range
(
0
,
1001
):
for
b
in
range
(
0
,
1001
):
c
=
1000
-
a
-
b
if
a
**
2
+
b
**
2
==
c
**
2
:
print
(
'a,b,c三个数分别为'
,
a
,
b
,
c
)
end_time
=
time
.
time
()
result
=
end_time
-
start_time
print
(
'计算总消耗时间为:'
,
result
)
\ No newline at end of file
diy2.py
View file @
95038bc6
#冒泡排序:从小到大,从大到小
#重复比较两个相邻元素
#排序n-1轮
alist
=
[
88
,
75
,
72
,
82
,
90
,
85
,
78
,
91
]
alist
=
[
88
,
75
,
72
,
82
,
90
,
85
,
78
,
91
]
n
=
len
(
alist
)
for
i
in
range
(
0
,
n
-
1
):
#排序n-1轮
for
j
in
range
(
0
,
n
-
1
):
#遍历列表元素下标
if
alist
[
j
]
>
alist
[
j
+
1
]:
alist
[
j
],
alist
[
j
+
1
]
=
alist
[
j
+
1
],
alist
[
j
]
print
(
alist
)
diy3.py
0 → 100644
View file @
95038bc6
import
time
start_time
=
time
.
time
()
list1
=
[]
for
a
in
range
(
0
,
1000
):
for
b
in
range
(
0
,
1000
):
list1
.
append
(
0
)
end_time
=
time
.
time
()
result
=
end_time
-
start_time
print
(
'计算总消耗时间为:'
,
result
)
\ 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