
Patrick B. answered 11/17/20
Math and computer tutor/teacher
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
print("Hello world")
class Plant:
def __init__(self, name,state):
self.name = name
self.state = state
def SetState(self,state):
self.state=state
def Water(self):
if self.state=='alive':
self.state='sated'
elif self.state=='sated':
self.state='dead'
def Place_in_sun(self):
if self.state=='sated':
self.state='alive'
elif self.state=='alive':
self.state='dead'
def __str__(self):
return('Plant[name='+self.name +',state='+self.state+']')
d = Plant('Fido','alive')
e = Plant('Buddy','alive')
f = Plant('Bernie','alive')
print(d.name)
print(e.name)
print(f.name)
f.SetState('dead')
e.Water()
d.Place_in_sun()
e.Place_in_sun()
print(d.__str__())
print(e.__str__())
print(f.__str__())