Skip to content

Instantly share code, notes, and snippets.

@chicagowebmanagement
Last active April 29, 2019 00:42
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/ec4b35e1676a601f4cbb832245489949 to your computer and use it in GitHub Desktop.
Save chicagowebmanagement/ec4b35e1676a601f4cbb832245489949 to your computer and use it in GitHub Desktop.
create a simple circle and output the area
"""
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