Commit ef9c1d1f by BellCodeEditor

auto save

parent 9bf2c303
Showing with 65 additions and 0 deletions
# 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
# 实例化玩家角色时,会自动打印出玩家角色的详细信息
# 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('后羿','射手')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment