Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson13-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
4558b672
authored
Oct 05, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
5ec53ebb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
0 deletions
1.py
2.py
3.py
4.py
diy.py
1.py
0 → 100644
View file @
4558b672
i
=
3
#设置变量i,代表登录的次数
username
=
"python"
#代表系统内存放的用户名
userpassword
=
"123456"
#代表系统内存放的用户密码
while
True
:
#重复执行
if
i
>
0
:
#判断,如果i>0,也就是还有登录次数,就执行如果里面的代码
name
=
input
(
"请输入用户名:"
)
#实现用户输入用户名
password
=
input
(
"请输入密码:"
)
#实现用户输入用户密码
i
-=
1
#每输入一次就把登录次数减少1
if
name
==
username
and
password
==
userpassword
:
#如果输入的用户名密码和系统中的用户名密码一样,就显示登录成功
print
(
"登录成功!"
)
break
#跳出循环
if
name
!=
username
:
#如果输入的用户名和系统内已有的用户名不一样,就提示输入错误
print
(
"用户名错误,请重新输入!"
)
print
(
'温馨提示,您还有'
+
str
(
i
)
+
"次机会"
)
continue
#结束本次循环,进入下一次循环
if
password
!=
userpassword
:
#如果输入的密码和系统内已有的密码不一样,就提示输入错误
print
(
"密码输入有误,请重新输入!"
)
print
(
'温馨提示,您还有'
+
str
(
i
)
+
"次机会"
)
else
:
#如果没有登录次数了,就显示以下的内容
print
(
"你的账户已被锁定,请一个小时以后再来"
)
exit
()
#结束运行
print
(
"欢迎来到贝尔编程!"
)
#登录成功后,显示的内容
2.py
0 → 100644
View file @
4558b672
class
Hero
:
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
250
self
.
attack
=
40
self
.
name
=
name
def
combat
(
self
,
enemy
):
# 普通攻击
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
enemy
.
hp
-=
self
.
attack
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
3.py
0 → 100644
View file @
4558b672
class
TheStudent
:
\ No newline at end of file
4.py
0 → 100644
View file @
4558b672
with
open
(
r"C:\Users\admin\Desktop\bell.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
file
.
write
(
"锦瑟[唐]
\n
李商隐
\n
锦瑟⽆端五⼗弦,
\n
⼀弦⼀柱思华年。
\n
庄⽣晓梦迷蝴蝶,
\n
"
)
file
.
write
(
"望帝春⼼托杜鹃。
\n
沧海⽉明珠有泪,
\n
蓝⽥⽇暖⽟⽣烟。
\n
此情可待成追忆,
\n
只是当时已惘然。
\n
"
)
new_i
=
""
with
open
(
r"C:\Users\admin\Desktop\bell.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
file
:
for
i
in
file
:
if
"蓝⽥⽇暖⽟⽣烟。"
in
i
:
i
=
i
.
replace
(
"蓝⽥⽇暖⽟⽣烟。"
,
"_____________"
)
new_i
+=
i
with
open
(
r"C:\Users\admin\Desktop\bell.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
file
.
write
(
new_i
)
\ No newline at end of file
diy.py
View file @
4558b672
with
open
(
r"c:\Users\admin\Documents\lesson13-1\sales_list.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
file1
:
a
=
file1
.
readlines
()
for
i
in
a
:
data
=
i
.
split
()
#print(data[1:])
sum
=
0
for
b
in
data
[
1
:]:
sum
=
sum
+
int
(
b
)
c
=
data
[
0
]
+
str
(
sum
)
print
(
c
)
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