Last active
April 29, 2019 00:42
-
-
Save chicagowebmanagement/ec4b35e1676a601f4cbb832245489949 to your computer and use it in GitHub Desktop.
create a simple circle and output the area
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: 04/26/2019 | |
Create a Circle class with a method called area that calculates and returns its area. | |
Then create a Circle object, call area on it, and print the result. | |
Use Python's pi function in the built-in math module. | |
import math | |
class Circle(): | |
def __init__(self, radius): | |
self.radius = radius | |
def calculate_area(self): | |
return self.radius ** 2 * math.pi | |
a_circle = Circle(4) | |
print(a_circle.calculate_area()) | |
""" | |
import math | |
class Circle(): | |
def __init__(self,radius): | |
self.radius=radius | |
self.calculate_area= math.pi * self.radius**2 | |
marshmellows=Circle(5) | |
print(marshmellows.calculate_area) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment