To get experience writing a functions.
For this lab you will write a program which calculates a few properties of rectangles. Each will be done with a separate function. The three functions you should write are:
This function should take the height and width of the rectangle and return the area of the rectangle. which is the product of the two.
This function should take the height and width of the rectangle and return the perimeter, which is the sum of all four sides.
This function should take the height and width and return a boolean indicating whether or not the rectangle is also a square.
Use the following code to fill out the rest of the program:
height = int(input("Enter the rectangle's height: ")) width = int(input("Enter the rectangle's width: ")) print("The area is", area(height, width)) print("The perimeter is", perimeter(height, width)) if isSquare(width, height): print("This rectangle is a square.") else: print("This rectangle is not a square.")
You shouldn't need to change this at all. If you write the three functions above this, then it should work.
Here is an example run of this program. Be sure to also test case where the rectangle is a square to make sure that function is working correctly.
Enter the rectangle's height: 7 Enter the rectangle's width: 5 The area is 35 The perimeter is 24 This rectangle is not a square.
When your program is finished, email the .py file to firstname.lastname@example.org.
Copyright © 2019 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.