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
90fb3d7e
authored
Feb 20, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
7721f7d0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
24 deletions
diy.py
类和对象.py
diy.py
View file @
90fb3d7e
with
open
(
r'C:\Users\10839\Desktop\sales_list.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
#c:\Users\10839\Desktop\sales_list.txt
with
open
(
r'c:\Users\10839\Desktop\sales_list.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
a
=
file
.
readlines
()
a
=
file
.
readlines
()
final_s
um
=
[]
final_s
alelist
=
[]
for
i
in
a
:
for
i
in
a
:
data
=
i
.
split
()
data
=
i
.
split
()
sum
=
0
sum
=
0
for
sales
in
data
[
1
:]:
for
sales
in
data
[
1
:]:
sum
+=
int
(
sales
)
sum
+=
int
(
sales
)
result
=
data
[
0
]
+
str
(
sum
)
+
'
\n
'
result
=
data
[
0
]
+
str
(
sum
)
+
'
\n
'
final_sum
.
append
(
result
)
final_salelist
.
append
(
result
)
with
open
(
r'C:\Users\10839\Desktop\sales_list.txt'
,
'a'
,
encoding
=
'utf-8'
)
as
file
:
with
open
(
r'c:\Users\10839\Desktop\new_sum.txt'
,
'a'
,
encoding
=
'utf-8'
)
as
file
:
file
.
writelines
(
final_sum
)
file
.
writelines
(
final_salelist
)
类和对象.py
View file @
90fb3d7e
class
Hero
:
class
Hero
:
class
Hero
:
class
Hero
:
def
__init__
(
self
,
name
,
hp
,
attack
):
#self后的都是形参
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
level
=
1
self
.
hp
=
300
self
.
attack
=
20
self
.
name
=
name
self
.
name
=
name
self
.
hp
=
hp
#4、5、6行都是实例化属性
def
combat
(
self
,
enemy
):
self
.
attack
=
attack
info1
=
self
.
name
+
'对'
+
enemy
.
name
+
'发起攻击造成'
+
str
(
self
.
attack
)
+
'点伤害'
def
upgrade
(
self
):
enemy
.
hp
-=
self
.
attack
self
.
level
=
self
.
level
+
1
if
enemy
.
hp
>
0
:
self
.
hp
=
self
.
hp
+
50
info2
=
enemy
.
name
+
'还剩'
+
str
(
enemy
.
hp
)
+
'血量'
self
.
attack
=
self
.
attack
+
20
info
=
info1
+
info2
yase
=
Hero
(
"亚瑟"
,
300
,
20
)
#实例化对象,300、80是实参,传参的数量顺序要和形参一致
print
(
info
)
houyi
=
Hero
(
"后羿"
,
200
,
30
)
else
:
#print(yase.name,yase.hp,yase.attack)
info2
=
enemy
.
name
+
'已阵亡,游戏结束'
#print(houyi.name,houyi.hp,houyi.attack)
info
=
info1
+
info2
yase
.
upgrade
()
print
(
info
)
houyi
.
upgrade
()
exit
()
print
(
yase
.
level
,
yase
.
hp
,
yase
.
attack
)
yase
=
Hero
(
'亚瑟'
)
print
(
houyi
.
level
,
houyi
.
hp
,
houyi
.
attack
)
houyi
=
Hero
(
'后羿'
)
\ No newline at end of file
yase
.
combat
(
houyi
)
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