Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson4_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
41ec0f2c
authored
Apr 14, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
370cf254
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
6 deletions
1.py
2.py
3.py
diy1.py
1.py
0 → 100644
View file @
41ec0f2c
import
turtle
def
fang
():
for
i
in
range
(
4
):
turtle
.
forward
(
100
)
turtle
.
right
(
90
)
turtle
.
penup
()
turtle
.
goto
(
-
100
,
100
)
turtle
.
pendown
()
turtle
.
color
(
"black"
)
turtle
.
begin_fill
()
fang
()
turtle
.
end_fill
()
turtle
.
goto
(
0
,
100
)
fang
()
turtle
.
goto
(
0
,
0
)
turtle
.
begin_fill
()
fang
()
turtle
.
end_fill
()
turtle
.
goto
(
-
100
,
0
)
fang
()
turtle
.
hideturtle
()
turtle
.
done
()
\ No newline at end of file
2.py
0 → 100644
View file @
41ec0f2c
# c=int(input())
# a=1
# b=1
# e=[]
# for i in range(c-2):
# d=a+b
# e.append(d)
# b=a
# a=d
# print(e)
a
=
int
(
input
())
b
=
[
1
,
1
]
for
i
in
range
(
2
,
a
):
b
.
append
(
b
[
i
-
1
]
+
b
[
i
-
2
])
print
(
b
)
\ No newline at end of file
3.py
0 → 100644
View file @
41ec0f2c
from
collections
import
deque
#collections是Python内建的一个集合模块,提供了许多有用的集合类。deque是队列类,可创建一个双端队列
# graph是一张以you为主体的人际关系网,值是键对应的朋友
graph
=
{}
graph
[
"you"
]
=
[
"alice"
,
"bob"
,
"claire"
]
graph
[
"bob"
]
=
[
"anuj"
,
"peggy"
]
graph
[
"alice"
]
=
[
"peggy"
]
graph
[
"claire"
]
=
[
"thom"
,
"jonny"
]
graph
[
"anuj"
]
=
[]
graph
[
"peggy"
]
=
[]
graph
[
"thom"
]
=
[]
graph
[
"jonny"
]
=
[]
# 判断是否是水果商
def
person_is_seller
(
name
):
return
name
[
-
1
]
==
'm'
#这里简单以名字最后一个字母是m的人作为水果商
# 查找人际关系网中是否有水果商
def
search
(
name
):
search_queue
=
deque
()
#创建一个队列
search_queue
+=
graph
[
name
]
#初始入队,将you的直接朋友入队
searched
=
[]
#已检查过的人,防止是2个人共同的朋友被重复检查
while
search_queue
:
#如果队列不为空,则继续检查
person
=
search_queue
.
popleft
()
#第一个出队检查
if
not
person
in
searched
:
#防止重复检查,最糟糕时会导致无限循环检查
if
person_is_seller
(
person
):
#是水果商
print
(
person
+
'是水果商。'
)
return
True
else
:
#不是水果商
search_queue
+=
graph
[
person
]
#将被检查人的朋友入队
searched
.
append
(
person
)
#将检查过的人添加到已测list中,防止重复检查
print
(
'你的人际关系网中无水果商。'
)
return
False
#人际关系网中无水果商
search
(
'you'
)
diy1.py
View file @
41ec0f2c
username
=
"python"
# 保存在服务器数据库中的用户账号(正确的账号)
username
=
"python"
# 保存在服务器数据库中的用户账号(正确的账号)
userpassword
=
"123456"
# 保存在服务器数据库中的用户密码(正确的密码)
userpassword
=
"123456"
# 保存在服务器数据库中的用户密码(正确的密码)
i
=
0
# 请用input()实现用户输入账号、密码的功能
# 请用input()实现用户输入账号、密码的功能
while
True
:
if
i
<
3
:
a
=
input
(
"用户名:"
)
# 如果用户输入的账号、密码正确,提示登陆成功
b
=
input
(
"密码:"
)
\ No newline at end of file
i
+=
1
print
(
i
)
if
a
==
username
and
b
==
userpassword
:
print
(
"登录成功!"
)
break
if
a
!=
username
:
print
(
"用户名错误!"
)
print
(
"您还有
%
s次输入次数"
%
(
3
-
i
))
continue
if
b
!=
userpassword
:
print
(
"密码错误!"
)
print
(
"您还有
%
s次输入次数"
%
(
3
-
i
))
else
:
print
(
"超出次数,账户已锁!"
)
exit
()
print
(
"欢迎进入系统"
)
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