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
53db1957
authored
May 05, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
061e9f8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
15 deletions
diy1.py
while.py
diy1.py
View file @
53db1957
username
=
"python"
# 保存在服务器数据库中的用户账号(正确的账号)
username
=
"python"
userpassword
=
"123456"
# 保存在服务器数据库中的用户密码(正确的密码)
userpassword
=
"123456"
while
True
:
#用循环实现登录错误和成功的效果
while
True
:
name
=
input
(
"请输入账号:"
)
# 请用input()实现用户输入账号、密码的功能
name
=
input
(
"请输入用户名:"
)
word
=
input
(
"请输入密码:"
)
#新建两个变量存储输入的账号和密码
password
=
input
(
"请输入密码:"
)
if
name
==
username
and
word
==
userpassword
:
# 如果用户输入的账号、密码正确,提示登陆成功;用存储的两个变量与数据库中保存的账号和密码进行比较
if
name
==
username
and
password
==
userpassword
:
print
(
"登录成功"
)
print
(
"登录成功!"
)
break
#登录成功跳出循环
break
print
(
"账号密码输入错误,请重新输入!"
)
#登录失败提示继续输入
if
name
!=
username
:
print
(
"欢迎来到贝尔编程"
)
#登录成功跳出循环后输出提示
print
(
"用户名错误,请重新输入!"
)
continue
if
password
!=
userpassword
:
print
(
"密码输入有误,请重新输入!"
)
print
(
"欢迎来到贝尔编程!"
)
\ No newline at end of file
while.py
View file @
53db1957
username
=
"python"
# 保存在服务器数据库中的用户账号(正确的账号)
username
=
"python"
# 保存在服务器数据库中的用户账号(正确的账号)
userpassword
=
"123456"
# 保存在服务器数据库中的用户密码(正确的密码)
userpassword
=
"123456"
# 保存在服务器数据库中的用户密码(正确的密码)
i
=
3
#设置变量来限制输入次数
while
True
:
#用循环实现登录错误和成功的效果
while
True
:
#用循环实现登录错误和成功的效果
name
=
input
(
"请输入账号:"
)
# 请用input()实现用户输入账号、密码的功能
if
i
>
0
:
#判断变量是否大于0,小于0就提示账号被锁定
word
=
input
(
"请输入密码:"
)
#新建两个变量存储输入的账号和密码
i
-=
1
#记录i的变化每次循环都会减1
if
name
==
username
and
word
==
userpassword
:
# 如果用户输入的账号、密码正确,提示登陆成功;用存储的两个变量与数据库中保存的账号和密码进行比较
name
=
input
(
"请输入账号:"
)
# 请用input()实现用户输入账号、密码的功能
print
(
"登录成功"
)
word
=
input
(
"请输入密码:"
)
#新建两个变量存储输入的账号和密码
break
#登录成功跳出循环
if
name
==
username
and
word
==
userpassword
:
# 如果用户输入的账号、密码正确,提示登陆成功;用存储的两个变量与数据库中保存的账号和密码进行比较
print
(
"登录成功"
)
break
#登录成功跳出循环
if
name
!=
username
:
#判断用户输入的账号是否正确
print
(
"用户名错误,请重新输入!"
)
continue
if
word
!=
userpassword
:
#判断输入的密码是否正确
print
(
"用户名错误,请重新输入!"
)
else
:
print
(
"你的账号已经被锁定,请带好身份证来我司解锁!"
)
exit
()
print
(
"欢迎来到贝尔编程"
)
#登录成功跳出循环后输出提示
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