Need help with the following (main file only, run the code):…
Question Answered step-by-step Need help with the following (main file only, run the code):… Need help with the following (main file only, run the code): Testing your code in Main.py:1. Create/make 2 lists, one to hold crops, another to hold fertilizers2. Populate the crops list with 10 crops with the first crop having a growth rate of 1, second having a growth rate of 2, etc. Don’t create/make 10 crops manually, try and use some loops to accomplish this.3. Populate the fertilizer list with 10 different fertilizers in a similar fashion but have the quantities vary, first having 1, second having 2, etc. Again, try to use loops for this.4. Loop over the lists and apply the fertilizer from the same position in the fertilizer list to the same position in the crop list, I.E. index 0 crop gets fertilized with index 0 fertilizer, index 1 crop with index 1 fertilizer, etc.5. For the very first crop since 1 fertilizer isn’t very much apply a second fertilizer of your choice to that crop to test out the multiple ferilizers being added6. Create/make another loop to go over the crop list and water each of the plants 10 times and print out each crop after each water, if you havent already override the print(the __str__ method) for crops to print out all the information about the crop.7. Examine the output and verify it is as you expect it should be.8. Repeat steps 1-5 but this time in the water loop check if the plant is ready to harvest after watering and if so harvest it and print out a message similar to “crop at index 3 harvested”. This step should be code separate from the previous steps so you should be able to largely copy and paste and maybe rename things to show they are separate, add a comment above the section that you put the code for step 7.9. Since the goal of this lesson is to get you to learn to use main to test how your code functions feel free to also do individual tests on a singular instance of a crop that demonstrate your code is functioning as it should. You could even create a singular crop and fertilizer and manuallly print out the expected values for the crop and fertilizer before watering, fertilizing, and harvesting and then print out the actual values. putt as many prints as you feel necessary in order to test your code in every way possible.10. If you see anything that doesn’t appear to be the right values throughout any of these steps do your best to correct your crop and fertilizer classes to function as they should.11. For fun change the 10 for the list sizes to 1000 FERTILIZER CLASS class Fertilizer: def __init__(self, quantity, growthModifier): self.quantity = quantity self.growthModifier = growthModifier CROP CLASS class Crop: def __init__(self, cropType, growthRate, isAlive=True, timesOverwatered=0): self.cropType = cropType self.growth = 0 self.growthRate = growthRate self.fertilized = 0 self.isAlive = True self.timesOverwatered = 0 def water(self): if self.growth >= 100: self.timesOverwatered += 1 if self.fertilized > 0: self.fertilized -= 1 if self.timesOverwatered >= 3: self.isAlive = False else: if self.fertilized > 0: self.growth += self.growthRate * self.fertilizer_growth_modifier self.fertilized -= 1 else: self.growth += self.growthRate if self.growth > 100: self.growth = 100 def harvest(self): if self.isAlive is False: return 0 if(self.growth >= 100): self.growth = 0 return 1 else: return 0 def fertilizer(self, fertilizer): if self.fertilizer is None: self.fertilizer = fertilizer self.fertilized = fertilizer.quantity self.fertilizer_growth_modifier = fertilizer.growth_modifier new_quantity = self.fertilizer.quantity + fertilizer.quantity new_growthRate = (self.fertilizer.growthRate + fertilizer.growthRate) / 2 self.fertilizer = fertilizer(new_quantity, new_growthRate) MAIN FILEfrom fertilizer import Fertilizer c1 = Crop(“Green pepper”, 2)c2 = Crop(“Corn”, 2) print(‘before fertilizer’)c1.water()c2.water()print(c1)print(c2)#print(c1.growth)print(‘nfertilized’)getTest = Fertilizer(4,16)getTest2 = Fertilizer(5,20)c1.fertilizer(getTest)c2.fertilizer(getTest2)print(c1)print(c2) #c1.fertilized()#print(c1.fertilized)#print(c1.growth)print(‘nwater after fertilize’)c1.water()c2.water()print(c1)print(c2) Computer Science Engineering & Technology Python Programming ICS 141 Share QuestionEmailCopy link Comments (0)


