class Cacykator:
def __zsq_sound(text):
def zsq(fun):
def inner(self,n):
self.__say(text+str(n))
return fun(self,n)
return inner
return zsq
def __zsq(fun):
def inner(self,num):
if not isinstance(num,(int,float)):
raise TypeError("数据类型错误")
return fun(self,num)
return inner
def __say(self,text):
import pyttsx3
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
@__zsq
@__zsq_sound("")
def __init__(self,num:(int,float)=0):
self.__result = num
@__zsq
@__zsq_sound("加上")
def add(self,num):
self.__result += num
return self
@__zsq
@__zsq_sound("减去")
def mul(self,num):
self.__result -= num
return self
@__zsq
@__zsq_sound("乘以")
def chen(self,num):
self.__result *= num
return self
@__zsq
@__zsq_sound("除以")
def mod(self,num):
self.__result /= num
return self
def show(self):
self.__say("={}".format(self.__result))
@property
def result(self):
return self.__result
Cacykator(100).add(10).mul(10).mod(10).chen(1000).show()
python面向对象
最新推荐文章于 2024-08-22 22:01:15 发布