mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-14 05:06:55 +01:00
Corrected ex1, ready to push
This commit is contained in:
@@ -4,33 +4,44 @@ class SecurePlant:
|
||||
__age: int
|
||||
|
||||
def set_height(self, height: int) -> None:
|
||||
"""Set height to plant"""
|
||||
if height < 0:
|
||||
print("Invalide operation attempted: height", height, "cm [REJECTED]")
|
||||
|
||||
print("Invalide operation attempted: height ",
|
||||
height, "cm [REJECTED]", sep="")
|
||||
print("Secrity: Negative height rejected")
|
||||
else:
|
||||
self.__height = height
|
||||
print("Height updated: ", height, "cm [OK]", sep="")
|
||||
|
||||
def set_age(self, age: int) -> None:
|
||||
"""Set age to plant"""
|
||||
if age < 0:
|
||||
print("Invalide operation attempted: age", age, "days [REJECTED]")
|
||||
print("Security: Negative age rejected")
|
||||
else:
|
||||
self.__age = age
|
||||
print("Age updated:", age, "days [OK]")
|
||||
|
||||
def get_height(self) -> int:
|
||||
"""Get plant height"""
|
||||
return self.__height
|
||||
|
||||
def get_age(self) -> int:
|
||||
"""Get plant age"""
|
||||
return self.__age
|
||||
|
||||
def __init__(self, name: str, height: int, age: int):
|
||||
def __init__(self, name: str, height: int, age: int) -> None:
|
||||
"""Init plant with his value"""
|
||||
self.name = name
|
||||
self.__height = height
|
||||
self.__age = age
|
||||
self.set_height(height)
|
||||
self.set_age(age)
|
||||
print("Plant created:", name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
plant = SecurePlant("Rose", 10, 3)
|
||||
print(plant.name, plant.get_height(), plant.get_age())
|
||||
plant.set_height(-10)
|
||||
plant.set_height(25)
|
||||
plant.set_age(30)
|
||||
print(plant.name, plant.get_height(), plant.get_age())
|
||||
plant.set_height(-10)
|
||||
print("Current plant: ", plant.name, " (", plant.get_height(),
|
||||
"cm, ", plant.get_age(), " days)", sep="")
|
||||
|
||||
Reference in New Issue
Block a user