def __init__(self, variety, ripeness='unripe'):
self.variety = variety
self.ripeness = ripeness
self.is_picked = False
def ripen(self):
if not self.is_picked:
if self.ripeness == 'unripe':
print(f"The {self.variety} apple is ripening.")
self.ripeness = 'ripe'
elif self.ripeness == 'ripe':
print(f"The {self.variety} apple is already ripe.")
else:
print(f"The {self.variety} apple has been picked and cannot ripen further.")
def pick(self):
if not self.is_picked:
print(f"Picking the {self.variety} apple.")
self.is_picked = True
else:
print(f"The {self.variety} apple has already been picked.")
def describe(self):
print(f"This is a {self.ripeness} {self.variety} apple.")
if name == "main": # Create a green apple instance apple = GreenApple(variety="Granny Smith")
# Describe the apple
apple.describe()
# Ripen the apple
apple.ripen()
# Pick the apple
apple.pick()
# Try to ripen the apple after picking
apple.ripen()
# Describe the apple again
apple.describe()