classIndex (object):def __init__(self,index_name,index_code,closeprice_yesterday,closeprice_today): Self.index_code=Index_code Self.index_name=index_name Self.closeprice_yesterday=Closeprice_yesterday Self.closeprice_today=Closeprice_todaydefdisplay (self):Print(("%s"+" "+"%s"+" "+"%s"+" "+"%s"+" "+"%s")%(self.index_name,self.index_code,self.closeprice_yesterday,self.closeprice_today))defprofit (self): Index_profit= (self.closeprice_today-self.closeprice_yesterday)/Self.closeprice_yesterdayreturnIndex_profit index300=index ("Shanghai","000300", 5306.59,5064.82) index50=index ("Shanghai","000016", 3347.12,3179.65) index500=index ("Chinese Certificate","000905", 11366.29,10879.84)Print("----------Index yield calculation results---------------")Print(index300.index_name+"Rate of return:"+str (Index300.profit () *100) +"%")Print(index50.index_name+"Rate of return:"+str (Index50.profit () *100) +"%")Print(index500.index_name+"Rate of return:"+str (Index500.profit () *100) +"%")
The output results are as follows:
----------Index yield calculation----------------4.55603315877%-5.00340591314%-4.27976059031%
python-Object-oriented (example of exponential object)