Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_3
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
ef9c1d1f
authored
Apr 22, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9bf2c303
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
1.py
demo1.py
1.py
0 → 100644
View file @
ef9c1d1f
# def func(n):
# if n==10:
# return 1
# sum=(func(n+1)+1)*2
# return sum
# a=func(1)
# print(a)
# 1、定义一个递归函数,函数名自取;
# 2、能够接收一个num的整数参数
# 3、函数能计算1+2+3+4...num的结果
# 如果定义的函数为func(num),那么func(num)=num + func(num-1);
# 当num等于1的时候,func(1)返回值为1
# def func(num):
# if num==100:
# return 100
# temp=func(num+1)
# return temp+num
# print(func(66))
def
func
(
n
):
if
n
<=
2
:
return
1
elif
n
>
2
:
value
=
func
(
n
-
1
)
+
func
(
n
-
2
)
return
value
a
=
func
(
24
)
print
(
a
)
\ No newline at end of file
demo1.py
0 → 100644
View file @
ef9c1d1f
# 实例化玩家角色时,会自动打印出玩家角色的详细信息
# 1、声明"角色xx创建成功,英雄类型为:xx"
# 2、打印出角色的属性值:等级、血量、攻击力
# 当调用类的时候,类里面的_init0绘自动执行一遍,所以可以把打印信息的代码放到_init_方法里面
class
Hero
:
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
level
=
1
self
.
hp
=
250
self
.
attack
=
40
self
.
max_hp
=
self
.
hp
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
()
class
Player
(
Hero
):
#继承Hero类
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
#玩家继承父类属性
self
.
name
=
name
#玩家的名字
self
.
attack
=
50
self
.
hp
=
200
self
.
h_type
=
hero_type
print
(
'角色'
+
self
.
name
+
'创建成功,类型为'
+
self
.
h_type
)
print
(
'等级,血量,攻击力分别为:'
,
self
.
level
,
self
.
hp
,
self
.
attack
)
yase
=
Hero
(
"垭瑟"
)
houyi
=
Player
(
'后羿'
,
'射手'
)
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