In: Computer Science
Hey, I have a code that I am working on to make a garden plot calculator, however I am reaching an error that I cannot seem to get past. Please help.
import math # GarednPlot contains all the utility functions class GardenPlot: # constructor function: Welcomes the user and sets default values def __init__(self): print("Welcome!") self.length = 0 self.radius = 0 self.depth = 0 # Sets the length of the GardenPlot and returns that length def setLength(self): self.length = float(input("Enter length of the garden: ")) return self.length # Sets the radius of the Fountain in the GardenPlot and returns that radius def setRadius(self): self.radius = float(input("Enter radius of the fountain: ")) return self.radius # Sets the depth of the GardenPlot/Flower-bed and returns that depth def setDepth(self): self.depth = float(input("Enter depth of the flower bed: ")) return self.depth # Returns the total area of the GardenPlot using the given formula def area_of_garden(self): return round((self.length * self.length), 1) # Returns the total area of the Fountain in the GardenPlot using the given formula def area_of_fountain(self): # round() rounds of the output to 1 decimal place return round((math.pi * self.radius * self.radius), 1) # Returns the total area of the flower bed def area_of_flowerbed(self): # Area of Flower-bed = Area of GardenPlot - Area of Fountain return round((self.area_of_garden() - self.area_of_fountain()), 1) # Returns the volume of the flower bed using the given formula def volume_of_soil(self): volume = self.area_of_flowerbed() * self.depth return round(volume, 1) # Prints the final stats of the Garden Plot def main(self): print("Total area of garden plot: "+ str(self.area_of_garden())) print("Total area of flower bed: "+ str(self.area_of_flowerbed())) print("Total amount of soil needed: "+ str(self.volume_of_soil())) # Driver function if __name__ == "__main__": # Create the object plot = GardenPlot() # Prompts user and displays all the inputs one after the other length = plot.setLength() print("Length: " + str(length)) radius = plot.setRadius() print("Radius: " + str(radius)) depth = plot.setDepth() print("Depth: " + str(depth)) # Print stats plot.main()
and here is the error that I keep recieving:
Enter length of the garden: Traceback (most recent call last): File "main.py", line 60, in <module> length = plot.setLength() File "main.py", line 15, in setLength self.length = float(input("Enter length of the garden: ")) EOFError: EOF when reading a line
The problem that you are getting is probably compier specific.
You did not call your def main() of the class GardenPlot . After calling the setters and calling the main of the class with random input following three output from three different platform are begin attached.
This is the code you have given.
plot.main() has been called at the end of calling the setters.
This code has been compiled on jupyter OnlinGDB and python command line interface.
This is the output you get in Jupyter
This is the output you get in OnlineGDB
This is the answer you get in command line execution
I am using the latest version of python that is python 3.9.
Please ask if any doubt is there