Exemplo n.º 1
0
    ##        self.pressure = pressure

    def circumference(self):
        'adjusted perimeter for width of tyre'
        return 1.25 * Circle.circumference(self)


t = Tyre(22)
print 'a tire of radius', 22
print 'has an area %.2f' % t.area()
print 'and a circumference %.2f' % t.circumference()

# Customer 3: National trucking company

print 'a hill of with 7 degree incline is a'
print '%d%% grade' % Circle.angle_to_grade(7)
print

# Customer 4: International graphics company
# We have money and power!
# We build circles NOT with radius
# but with a bounding box diagonal

c = Circle.from_bbd(10)
print 'a circle with bounding box diagonal 10'
print 'has a radius %.2f' % c.radius
print 'and an area %.2f' % c.area()
print

# Customer 5: the government
# We like to micromanage
def customer_3():
    angle = 7.0
    print 'a hill with {:.0f} degree incline'.format(angle)
    print 'is a {:.0f}% grade'.format(Circle.angle_to_grade(7))
Exemplo n.º 3
0
t = Tire(30)
print 'A tire with an inner radius of', t.radius
print 'has an inner area of', t.area()
print 'and outer perimeter of', t.perimeter()
print

m = MonsterTire(30)
print 'A monster tire with an inner radius of', m.radius
print 'has an inner area of', m.area()
print 'and outer perimeter of', m.perimeter()
print

## National Trucking Company ###################################

print u'An inclinometer reading of 5\N{degree sign}'
print 'is a %.1f%% percent grade' % Circle.angle_to_grade(5)
print

## National Graphics Company ###################################

c = Circle.from_bbd(30)
print 'A circle with bounding box diagonal 30'
print 'has a radius of', c.radius
print 'an area of', c.area()
print 'and a perimeter of', c.perimeter()
print

## U.S. Government #############################################

## ISO 10666: No circle software shall compute area directly from
## instance data. MUST first call perimeter() and infer the instance
Exemplo n.º 4
0
t = Tire(30)
print 'A tire with an inner radius of', t.radius
print 'has an inner area of', t.area()
print 'and outer perimeter of', t.perimeter()
print

m = MonsterTire(30)
print 'A monster tire with an inner radius of', m.radius
print 'has an inner area of', m.area()
print 'and outer perimeter of', m.perimeter()
print

## National Trucking Company #######################################

print u'An inclinometer reading of 5\N{degree sign}',
print 'is an %.1f%% grade.' % Circle.angle_to_grade(5)
print

# National Graphics Company ##################################

c = Circle.from_bbd(30)
print 'A circle with the bounding box diagonal of 30'
print 'has a radius of', c.radius
print 'an area of', c.area()
print 'and a perimeter of', c.perimeter()
print

## U.S. Government ###########################################

## ISO 10666:  No circle software shall compute the area
## directly from instance data.  It MUST first call
Exemplo n.º 5
0
    which instance (usually "self")
'''


# a tire with 22 inch rim
t = Tire(22)
print 'A tire of radius', t.radius
print 'has an area {:.2f}'.format(t.area())
print 'and circumference {:.2f}'.format(t.circumference())
print


# Customer 4: National Trucking Company

print 'an incline of 7 degrees'
print 'is a {:.0f} grade'.format(Circle.angle_to_grade(7))
print

#Customer 5: International Graphics company
# We have money and power!
# We build circles NOT with radius,
# But with a bounding box diagonal
# r = d / sqrt(r) or d^2 = 2r^2

c = Circle.from_bbd(5)
print 'a circle with diagonal 5'
print 'has a radius {:.2f}'.format(c.radius)
print 'and an area {:.2f}'.format(c.area())
print

Exemplo n.º 6
0
Arquivo: client.py Projeto: vish1/code
        # Overriding -- don't call the parent method
        # Extending -- call the parent method and then modify it's result
        return Circle.perimeter(self) * self.RUBBER_RATIO

    __perimeter = perimeter

t = Tire(30)
print 'A tire with an inner radius of', t.radius
print 'and inner area of', t.area()
print 'and an outer perimeter of', t.perimeter()
print

## National Trucking Company #####

print u'A 5\N{DEGREE SIGN} degree inclinometer reading',
print 'is %.1f%% grade' % Circle.angle_to_grade(5)
print 

## National Graphic Company #########

c = Circle.from_bbd(40)
print 'A circle with a bounding box diagonal of 40'
print 'has a perimeter of', c.perimeter()
print 'and a radius of', c.radius
print 'and an area of', c.area()
print


## US Government ###########

# ISO 10111: All circle software SHALL NOT access the radius directly.
Exemplo n.º 7
0
class Tire(Circle):

    def perimeter(self):
        'Perimeter adjusted for width of tire'
        return Circle.perimeter(self) * 1.25

t = Tire(22)
print 'a tire with radius', t.radius
print 'has an area %.0f' % t.area()
print 'and a perimeter %.0f' % t.perimeter()
print

# Customer 4: national trucking company
print 'a hill with inclinometer reading 7 degrees'
print 'is a percent grade: %.2f%%' % Circle.angle_to_grade(7)
print

# Customer 5: international graphics company
# We have money and power!
# We want the constructor to be based on the bounding box diagonal!
c = Circle.from_bbd(10)
print 'a circle with a bounding box diagonal 10'
print 'has a radius %.2f' % c.radius
print 'and an area %.2f' % c.area()
print

# Customer 6: the Feds
# We like to micromanage:
# we will tell you not just WHAT to do, but also HOW to do it
Exemplo n.º 8
0
class MonsterTire(Tire):

    __slots__ = []

    RUBBER_RATIO = 1.50


t = Tire(30)
print 'A tire with an inner raius of', t.radius
print 'has an area of', t.area()
print 'and has an outer perimeter of ', t.perimeter()
print

t = MonsterTire(30)
print 'A tire with an inner raius of', t.radius
print 'has an area of', t.area()
print 'and has an outer perimeter of ', t.perimeter()
print

## National Trucking Company ##############################################

print u'An inclinometer reading of 5\N{degree sign}',
print 'is a %f%% grade' % Circle.angle_to_grade(5)
print

## US Gov't ###############################################################

# ISO 10666: No circle software shall compute an area directly from
# instance data.  It MUST first call perimeter and infer the data indirectly.
    def perimeter(self):
        'adjusted perimeter for width of tire'
        return Circle.perimeter(self) * 1.25

    __perimeter = perimeter

t = Tire(22)
print ' tire with radius 22'
print 'has an area %.2f' % t.area()
print 'and a perimeter %.2f' % t.perimeter()
print

# Customer 4: National Trucking Co.
print 'an incline of 7 degres'
print 'is a %d percent grade' % Circle.angle_to_grade(7)
print

# Customer 5: International Graphics Co.
print 'We have money and power'
print 'We build circles with counding boxes not radius'
c = Circle.from_bdd(10)
print 'a Circle with a bounding box diagonal 10'
print 'has a radius', c.radius
print 'and an area', c.area()
print

# Customer 6: Federal Government
# We like to micromanage!
# We will tell you not only WHAT to do
# But also HOW to do it