Skip to content

Instantly share code, notes, and snippets.

@chicagowebmanagement
Last active May 3, 2019 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chicagowebmanagement/9ca6125259f0377736e851812d0d11c3 to your computer and use it in GitHub Desktop.
Save chicagowebmanagement/9ca6125259f0377736e851812d0d11c3 to your computer and use it in GitHub Desktop.
create classes and execute them
"""
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