Files
42-Piscine_Python/01/ex4/ft_garden_security.py
David Gailleton bedf955bd8 01/04
2025-12-22 15:32:34 +00:00

37 lines
948 B
Python

class SecurePlant:
name: str
__height: int
__age: int
def set_height(self, height: int) -> None:
if height < 0:
print("Invalide operation attempted: height", height, "cm [REJECTED]")
else:
self.__height = height
def set_age(self, age: int) -> None:
if age < 0:
print("Invalide operation attempted: age", age, "days [REJECTED]")
else:
self.__age = age
def get_height(self) -> int:
return self.__height
def get_age(self) -> int:
return self.__age
def __init__(self, name: str, height: int, age: int):
self.name = name
self.__height = height
self.__age = age
if __name__ == "__main__":
plant = SecurePlant("Rose", 10, 3)
print(plant.name, plant.get_height(), plant.get_age())
plant.set_height(-10)
plant.set_age(30)
print(plant.name, plant.get_height(), plant.get_age())