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
98db3cea
authored
Jun 16, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
cec87a77
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
17 deletions
diy.py/diy.py
diy.py/diy.py
View file @
98db3cea
class
hero
:
#
class hero:
def
__init__
(
self
,
name
,
hp
,
attack
):
#
def __init__(self,name,hp,attack):
self
.
level
=
1
#
self.level = 1
self
.
name
=
name
#
self.name = name
self
.
hp
=
hp
#
self.hp=hp
self
.
attack
=
attack
#
self.attack=attack
def
shenji
(
self
):
#
def shenji(self):
self
.
hp
=
self
.
hp
+
50
#
self.hp=self.hp+50
self
.
level
=
self
.
level
+
1
#
self.level=self.level+1
self
.
attack
=
self
.
attack
+
4
#
self.attack=self.attack+4
yase
=
hero
(
"yase"
,
300
,
200
)
# yase=hero("yase",300,200)
yase
.
shenji
()
# yase.shenji()
print
(
yase
.
hp
)
# print(yase.hp)
houyi
=
hero
(
"后裔"
,
200
,
400
)
# houyi = hero("后裔",200,400)
houyi
.
shenji
()
# houyi.shenji()
# print(houyi.hp)
# 创建一个cat类 每一只猫都有名字(name),年龄(age),性别(sex)
# 每一只猫都有吃东西的行为(print("猫在吃饭")).实例化出一只名字为aa,年龄为10,性别为男的猫 并在控制台打印猫在吃饭
class
cat
:
def
__init__
(
self
,
name
,
age
,
sex
,
hungry
):
self
.
name
=
name
self
.
age
=
age
self
.
sex
=
sex
self
.
hungry
=
hungry
def
eat
(
self
):
self
.
hungry
=
self
.
hungry
-
1
a
=
cat
(
"cat1"
,
11
,
"man"
,
5
)
b
=
cat
(
"cat2"
,
11
,
"man"
,
5
)
a
.
eat
()
a
.
name
=
"a猫"
print
(
a
.
name
)
print
(
b
.
hungry
)
print
(
houyi
.
hp
)
\ 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