Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Last active March 20, 2018 09:09
Show Gist options
  • Save prodeveloper/c6dda68b75c2077dada445d45d1736de to your computer and use it in GitHub Desktop.
Save prodeveloper/c6dda68b75c2077dada445d45d1736de to your computer and use it in GitHub Desktop.
Class Demo for rectangle and circle
import math
class Circle:
radius = 0
def __init__(self,radius):
self.radius = radius
def validateDimension(self):
try:
self.width = float(self.radius)
except ValueError:
raise ValueError("Radius provided is invalid")
def area(self):
return self.radius * self.radius * math.pi
sudo add-apt-repository ppa:git-core/ppa
name = "Judith"
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
self.validateDimension()
def validateDimension(self):
try:
self.width = float(self.width)
self.length = float(self.length)
except ValueError:
raise ValueError("Dimensions can not be converted to integer")
def area(self):
return self.length * self.width
def perimeter(self):
return 2*(self.length + self.width)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment