Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_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
c2015ece
authored
Apr 01, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
f3194c94
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
diy.py
test.py
diy.py
View file @
c2015ece
#定义英雄类
class
Hero
:
class
Hero
:
#定义属性
def
__init__
(
self
,
name
,
health
,
attack
):
#名称,血量,攻击力
self
.
hp
=
health
self
.
level
=
1
self
.
attack
=
attack
self
.
name
=
name
#定义类方法
def
upgrade
(
self
):
self
.
level
+=
1
self
.
hp
+=
50
self
.
attack
+=
10
#实例化对象
yase
=
Hero
(
'亚瑟'
,
300
,
20
)
houyi
=
Hero
(
'后裔'
,
250
,
30
)
#修改属性
houyi
.
upgrade
()
#测试
print
(
yase
.
attack
)
print
(
houyi
.
attack
)
\ No newline at end of file
test.py
0 → 100644
View file @
c2015ece
print
(
' '
+
'1'
)
\ No newline at end of file
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