Traktor/source/plant.py

41 lines
1.4 KiB
Python

import random
class Plant:
def __init__(self, name, plant_type, water_requirements, nutrients_requirements, growth_level):
self.name = name
self.plant_type = plant_type
self.water_requirements = water_requirements
self.nutrients_requirements = nutrients_requirements
self.growth_level = growth_level
def try_to_grow(self, water, nutrients):
if (water >= self.water_requirements) and (nutrients >= self.nutrients_requirements):
i = random.randint(5, 12)
if self.growth_level+i > 100:
i = 100 - self.growth_level
self.growth_level += i
print("The plant is growing")
else:
print("Unable to grow due to bad condition of the ground")
def update_name(self, predicted_class):
if predicted_class == "Apple":
self.name = "Apple"
self.plant_type = "fruit"
elif predicted_class == "Strawberry":
self.name = "Strawberry"
self.plant_type = "fruit"
elif predicted_class == "Cucumber":
self.name = "Cucumber"
self.plant_type = "vegetable"
elif predicted_class == "Cauliflower":
self.name = "Cauliflower"
self.plant_type = "vegetable"
elif predicted_class == "Wheat":
self.name = "Wheat"
self.plant_type = "cereal"