python3语句实现
1个回答
展开全部
#! usr/bin/python
# -*- coding:utf-8 -*-
#python 3.5
import sys
#精灵类
class Fairy:
'''
四个属性 体重 高度 颜色 血量
weight
height
color
power
'''
'''
自定义
行走消耗能量 1
跳跃消耗能量 2
进食增加能量 3
'''
run_ = -1
dump_ = -2
eat_ = 3
def __init__(self, weight,height,color,power):
self.weight = weight
self.height = height
self.color = color
self.power = power
''' 行走 run '''
def run(self,step):
self.power += self.run_*step
''' 跳跃 dump '''
def dump(self,step):
self.power += self.dump_*step
''' eat 进食'''
def eat(self,step):
self.power += self.eat_*step
fairy = Fairy(100,170,'red',100)
print (fairy.__dict__)
print('-----------------run 2 ---------------')
fairy.run(2)
print (fairy.__dict__)
print('-----------------dump 2 ---------------')
fairy.dump(2)
print (fairy.__dict__)
print('-----------------eat 2 ---------------')
fairy.eat(2)
print (fairy.__dict__)
============= RESTART: C:\Users\Administrator\Desktop\work\t2.py =============
{'height': 170, 'power': 100, 'weight': 100, 'color': 'red'}
-----------------run 2 ---------------
{'height': 170, 'power': 98, 'weight': 100, 'color': 'red'}
-----------------dump 2 ---------------
{'height': 170, 'power': 94, 'weight': 100, 'color': 'red'}
-----------------eat 2 ---------------
{'height': 170, 'power': 100, 'weight': 100, 'color': 'red'}
>>>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询