Chapter 12 The second question

#_author:来童星
#date:2019/12/13
from datetime import datetime
class medicine:
name=''
price=0
PD=''
Exp=''
def __init__(self,name,price,PD,Exp):
self.name=name
self.price=price
self.PD=PD
self.Exp=Exp
@property
def get_name(self):

return self.name
@property
def get_GP(self):
start=datetime.strptime(self.PD,'%Y-%m-%d')
end=datetime.strptime(self.Exp,'%Y-%m-%d')
return (end-start).days
m=medicine('格列宁',8000,'2019-5-31','2020-6-30')

print(format(m.get_name),format(m.get_GP))


The result:
Ge Liening 396

Guess you like

Origin www.cnblogs.com/startl/p/12036506.html