Question

In: Computer Science

Garden Plot Calculator Assume that you have a garden plot like the following: The blue circle...

Garden Plot Calculator

Assume that you have a garden plot like the following:

The blue circle represents a fountain and the orange part the flower bed. Remember that the area of a square is the length of oneof its sides squared. Also, the area of a circle is πr, where r is the radius of the circle. The volume is the square footage times thedepth.For this project, you get to write a Python script to perform some calculations for the garden plot, based on user input.

Write a Python 3 script that has functions do the following:

Welcome the user

Prompts the user for the length of one of the sides of the garden and returns that value

Prompts the user for the radius of the fountain and returns that value

Calculates the total square footage of the flower bed

Prompts the user for the depth of the flower bed and returns that value

Have your script display the total square footage of the garden plot, the square footage of just the flower bed and the amount of soil needed for the flower bed (in cubic foot)

. Use the math module for π.

Also, your script must appropriately include a main() function, which cannot be the longest function.

Additionally, round all calculations to 1 decimal place. Include a descriptive comment before each function and each major section of your code.

Solutions

Expert Solution

Ans: I have opted to use a class based python script to solve the given problem but if needed it can be easily converted to the function based python program by using instance members (ex:- length, depth, etc) in the class as global variables in function based program.

Code: Please read comments for code explanation.

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()

Related Solutions

Hey, I have a code that I am working on to make a garden plot calculator,...
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...
Plot the function without using a calculator, as you will not have a calculator on the...
Plot the function without using a calculator, as you will not have a calculator on the exams. a. ? = 34 sin ?, from t = 0 to the end of the first cycle only. b. ? = 2sin3?, from t = 0 to the end of the second cycle only. c. ? = 2cos3?, from t = 0 to the end of the second cycle only. d. ? = 2sin??, from t = 0 to the end of the...
Edit question Garden Glory Project Questions Assume that Garden Glory designs a database with the following...
Edit question Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER (OwnerID, OwnerName, OwnerEmail, OwnerType) OWNED_PROPERTY (PropertyID, PropertyName, PropertyType, Street, City, State, Zip, OwnerID) GG_SERVICE (ServiceID, ServiceDescription, CostPerHour); EMPLOYEE (EmployeeID, LastName, FirstName, CellPhone, ExperienceLevel) PROPERTY_SERVICE ( PropertyServiceID , PropertyID , ServiceID, ServiceDate , EmployeeID, HoursWorked) The referential integrity constraints are: OwnerID in OWNED_PROPERTY must exist in OwnerID in OWNER PropertyID in PROPERTY_SERVICE must exist in PropertyID in OWNED_PROPERTY ServiceID in PROPERTY_SERVICE must exist...
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER...
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER (OwnerID, OwnerName, OwnerEmail, OwnerType) OWNED_PROPERTY (PropertyID, PropertyName, PropertyType, Street, City, State, Zip, OwnerID) GG_SERVICE (ServiceID, ServiceDescription, CostPerHour); EMPLOYEE (EmployeeID, LastName, FirstName, CellPhone, ExperienceLevel) PROPERTY_SERVICE ( PropertyServiceID , PropertyID , ServiceID, ServiceDate , EmployeeID, HoursWorked) The referential integrity constraints are: OwnerID in OWNED_PROPERTY must exist in OwnerID in OWNER PropertyID in PROPERTY_SERVICE must exist in PropertyID in OWNED_PROPERTY ServiceID in PROPERTY_SERVICE must exist in ServiceID...
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER...
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER (OwnerID, OwnerName, OwnerEmail, OwnerType) OWNED_PROPERTY (PropertyID, PropertyName, PropertyType, Street, City, State, Zip, OwnerID) GG_SERVICE (ServiceID, ServiceDescription, CostPerHour); EMPLOYEE (EmployeeID, LastName, FirstName, CellPhone, ExperienceLevel) PROPERTY_SERVICE ( PropertyServiceID , PropertyID , ServiceID, ServiceDate , EmployeeID, HoursWorked) The referential integrity constraints are: OwnerID in OWNED_PROPERTY must exist in OwnerID in OWNER PropertyID in PROPERTY_SERVICE must exist in PropertyID in OWNED_PROPERTY ServiceID in PROPERTY_SERVICE must exist in ServiceID...
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER...
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER (OwnerID, OwnerName, OwnerEmail, OwnerType) OWNED_PROPERTY (PropertyID, PropertyName, PropertyType, Street, City, State, Zip, OwnerID) GG_SERVICE (ServiceID, ServiceDescription, CostPerHour); EMPLOYEE (EmployeeID, LastName, FirstName, CellPhone, ExperienceLevel) PROPERTY_SERVICE ( PropertyServiceID , PropertyID , ServiceID, ServiceDate , EmployeeID, HoursWorked) The referential integrity constraints are: OwnerID in OWNED_PROPERTY must exist in OwnerID in OWNER PropertyID in PROPERTY_SERVICE must exist in PropertyID in OWNED_PROPERTY ServiceID in PROPERTY_SERVICE must exist in ServiceID...
**can you explain how to solve on calculator** 1. Assume that adults have IQ scores that...
**can you explain how to solve on calculator** 1. Assume that adults have IQ scores that are normally distributed with a mean of 96.9 and a standard deviation of 19.9. Find the probability that a randomly selected adult has an IQ greater than 136.4 2. Find the area of the shaded region. The graph depicts the standard normal distribution of bone density scores with mean 0 and standard deviation 1. z= -.85, z= 1.26 3. Find the area of the...
How do you do this on a ti-84 calculator? Assume adult females have pulse rates that...
How do you do this on a ti-84 calculator? Assume adult females have pulse rates that are normally distributed with a mean of 74.0 beats per minute and a standard deviation of 12.5 beats per minute. If 16 adult females are randomly selected, find the probability that they have pulse rates with a mean between 78 beats per minute and 90 beats per minute.
Assume that you have $5,000 that you would like to invest. The company is AMAZON. Evaluate...
Assume that you have $5,000 that you would like to invest. The company is AMAZON. Evaluate the common stock as a potential investment. From the data available in the financial statements identify the five most important criteria that you would use to make your investment decision and explain why each is important. Use the ratios discussed in the chapters as well as anything else discussed throughout the term in your explanation. Indicate if you would or would not invest your...
Assume that you are planning to have a party at your house. You really would like...
Assume that you are planning to have a party at your house. You really would like to have the party outside in the sun, but there is a chance that it might rain. You have two decisions to make – whether or not you will watch the forecast and then whether to have the party inside or outside. If you choose to watch the forecast, it will either tell you that the weather will be sunny or that it will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT