Last active
May 3, 2019 17:11
-
-
Save chicagowebmanagement/9ca6125259f0377736e851812d0d11c3 to your computer and use it in GitHub Desktop.
create classes and execute them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Author: Patrick Elward | |
Date: 05/03/2019 | |
Create Rectangle and Square classes with a method called calculate_perimeter that calculates the perimeter of the shapes they represent. | |
Create Rectangle and Square objects and call the method on both of them. | |
""" | |
import math | |
class Rectangle: | |
def __init__(self,l,w): | |
self.l=l | |
self.w=w | |
self.perimeter=l+l+w+ w | |
class Square: | |
def __init__(self,s): | |
self.s=s | |
self.perimeter=s+s+s+s | |
rectangle=Rectangle(4,6) | |
print("Rectangle perimeter: ", rectangle.perimeter) | |
square=Square(7.4) | |
print("Square perimeter: ", square.perimeter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment