In: Computer Science
Use your IDE (PyCharm) to create a new file named countertop.py. Type in the following lines, exactly as they are shown here (including the four spaces before the indented lines of code) and save the file:
def countertop(sideLength):
""" Compute the area of a square countertop with a missing wedge.
The parameter x is the length of one side of the square. """
square = sideLength ** 2 # area of the full square
triangle = ((sideLength / 2) ** 2) / 2 # area of the missing wedge
return square - triangle.
Now we want to use the countertop function to calculate the area given the user’s input and print out the result. Take input from the user like we did in problem 1. Then call the countertop function and store the result in a variable, before printing that variable on the next line. Try running the program in the IDE
IDLE CODE
============================================================================================
def countertop(sideLength):
""" Compute the area of a square countertop with a missing
wedge.
The parameter x is the length of one side of the square. """
square = sideLength ** 2 # area of the full square
triangle = ((sideLength / 2) ** 2) / 2 # area of the missing
wedge
return square - triangle
side=float(input('Enter side length: '))
res=countertop(side)
print('output is: ',res)
============================================================================================
output