Last active
March 20, 2018 09:09
-
-
Save prodeveloper/c6dda68b75c2077dada445d45d1736de to your computer and use it in GitHub Desktop.
Class Demo for rectangle and circle
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
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 |
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
sudo add-apt-repository ppa:git-core/ppa |
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
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