Skip to main content

cs2370 Notes: 21 Flappy Bat

··1 min

Classes and Methods

Inheritence

from math import pi

class LawnShape:
    def area(self):
        raise Exception("not implemented")
    
    def cost(self, grassPrice):
        return self.area() * grassPrice

class Circle(LawnShape):
    def __init__(self, radius, cost):
        self.radius = radius
    
    def area(self):
        return pi * pow(self.radius, 2)

Example:

flappy bat v2