class MobilePhone:
def __init__(self,name):
self.name = name
self.battery = 5
def __str__(self):
return 'name:{},battery:{}'.format(self.name,self.battery)
def playGame(self):
'''
打游戏
:return:
'''
# 电量是否满足打游戏的条件
if self.battery>=10:
print('打游戏')
# 消耗10个电量
self.battery -= 10
else:
print('不能打游戏')
def listenMusic(self):
'''
听歌
:return:
'''
if self.battery >= 5:
print('听歌')
# 消耗10个电量
self.battery -= 5
else:
print('不能打听歌')
def call(self):
'''
打电话
:return:
'''
if self.battery >= 4:
print('打电话')
# 消耗10个电量
self.battery -= 4
else:
print('不能打打电话')
def receiveCall(self):
'''
接电话
:return:
'''
if self.battery >= 3:
print('接电话')
# 消耗10个电量
self.battery -= 3
else:
print('不能接电话')
def charge(self):
'''
充电
:return:
'''
print('充电')
self.battery += 10
# 定义手机对象
phone = MobilePhone('苹果手机')
phone.playGame()
phone.listenMusic()
phone.charge()
print(phone)