Home CPSC 110

Rectangle Functions

 

Objective

To get experience writing a functions.


 

Task

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:


 

Calling Code

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.


 

Example Run

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.

 

Submitting

When your program is finished, email the .py file to ifinlay@umw.edu.

Copyright © 2019 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.