HI, I'm new to python coding im trying to make a plant automation system and library. I'm trying to take a user input and run it against a list and if it is in the list call the plant_info function on please tell me if im even close to accomplishing this. I have copy of code attached . Any help would be appreciated
[
attachment=2744]
Post code, not links to code
Kindly paste your code here. then i will try to solve your issue
I'm not a specialist myself, but I would have add an additional method (see
def getPlant
here after) to get the plant name and to check if it is the same as the input string.
class Plant:
def __init__(self,name,family,water_level,ph,sunlight,fertilizer):
self.name=name
self.family=family
self.water_level=water_level
self.ph=ph
self.sunlight=sunlight
self.fertilizer=fertilizer
def watering(self):
if self.water_level=="Light":
print("WATERING....DONE")
elif self.water_level=="Medium":
print("WATERING...WATERING...DONE")
elif self.water_level=="Heavy":
print("WATERING...WATERING...WATERING...DONE")
else:
print("INVALID INPUT")
def plant_info(self):
print(self.name, " is a ",self.family," and has ",self.water_level," watering requirements, ", self.ph," PH Level"," and needs ",self.sunlight,"sunlight and a",self.fertilizer,"fertilizer")
def getPlant(self):
return self.name
Pepper=Plant('Pepper','Solanaceae', 'Medium','6.0','Bright','13-13-13')
Tomatoe=Plant('Tomatoe','Solanaceae', 'Medium','6.0','Bright','13-13-13')
Broccoli=Plant('Broccoli','Brassicaceae', 'Light','5.5', 'Partial Sun','13-10-10')
Plants=[]
Plants.append(Pepper)
Plants.append(Tomatoe)
Plants.append(Broccoli)
Plant_selection=input("PLEASE INPUT PLANT: ")
for p in Plants:
if (Plant_selection.lower() == p.getPlant().lower()): p.plant_info()
class Plant:
def __init__(self,name,family,water_level,ph,sunlight,fertilizer):
self.name=name
self.family=family
self.water_level=water_level
self.ph=ph
self.sunlight=sunlight
self.fertilizer=fertilizer
def watering(self):
if self.water_level=="Light":
print("WATERING....DONE")
elif self.water_level=="Medium":
print("WATERING...WATERING...DONE")
elif self.water_level=="Heavy":
print("WATERING...WATERING...WATERING...DONE")
else:
print("INVALID INPUT")
def plant_info(self):
print(self.name, " is a ",self.family," and has ",self.water_level," watering requirements, ", self.ph," PH Level"," and needs ",self.sunlight,"sunlight and a",self.fertilizer,"fertilizer")
Pepper=Plant('Pepper','Solanaceae', 'Medium','6.0','Bright','13-13-13')
Tomatoe=Plant('Tomatoe','Solanaceae', 'Medium','6.0','Bright','13-13-13')
Broccoli=Plant('Broccoli','Brassicaceae', 'Light','5.5', 'Partial Sun','13-10-10')
Plants=[]
Plants.append(Pepper)
Plants.append(Tomatoe)
Plants.append(Broccoli)
Plant_selection=input("PLEASE INPUT PLANT")
for Plant_selection in Plants:
Plant_selection.plant_info()