Posts: 2
Threads: 1
Joined: Feb 2024
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
Plant library and automation.py (Size: 1.26 KB / Downloads: 168)
Posts: 6,779
Threads: 20
Joined: Feb 2020
Post code, not links to code
Posts: 7
Threads: 0
Joined: Jan 2024
Kindly paste your code here. then i will try to solve your issue
Posts: 299
Threads: 72
Joined: Apr 2019
Feb-14-2024, 10:04 AM
(This post was last modified: Feb-14-2024, 02:03 PM by paul18fr.)
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()
Posts: 2
Threads: 1
Joined: Feb 2024
Feb-14-2024, 01:14 PM
(This post was last modified: Feb-14-2024, 02:17 PM by buran.)
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()
buran write Feb-14-2024, 02:17 PM:Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
|