Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_2
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
2da146fd
authored
Oct 06, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
c6188a1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
6 deletions
snake.py
snake.py
View file @
2da146fd
import
pygame
'''
创建一个函数,可以接受一个字符串,然后返回该字符串的第一个和最后一个字符。return
'''
def
new
(
a
):
b
=
a
[
0
]
c
=
a
[
-
1
]
return
b
,
c
# 初始化pygame,为使用pygame做准备
b
,
c
=
new
(
"python"
)
p
ygame
.
init
(
)
p
rint
(
b
,
c
)
# 创建一个窗口
??
\ No newline at end of file
'''
编程实现:求解1-1000以内所有能被9整除的数字。
'''
方法一
for
i
in
range
(
1
,
1001
):
if
i
%
9
==
0
:
print
(
i
)
方法二
for
i
in
range
(
9
,
1000
,
9
):
print
(
i
)
'''
编程实现:求列表list=[4,2,54,99,10,23]的和
'''
list
=
[
4
,
2
,
54
,
99
,
10
,
23
]
sum
=
0
# 累加器
for
i
in
list
:
sum
=
sum
+
i
print
(
"和是:"
,
sum
)
'''
求列表中所有奇数的和
'''
list
=
[
4
,
2
,
54
,
99
,
10
,
23
,
231
,
443
,
1213
,
5432
,
43
]
sum
=
0
# 累加器
for
i
in
list
:
if
i
%
2
==
1
:
sum
=
sum
+
i
print
(
"奇数和是:"
,
sum
)
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