示例#1
0
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
# we'll tell you not just WHAT to build
# but also HOW to build it

# ISO-12345-fake
# Thou shalt not directly access the radius
# inside area methods. Area methods must
# infer the radius from the circumference.
def customer_4():
    bbd = 10
    c = Circle.from_bbd(bbd)
    print 'a circle with bounding box diagonal of {}'.format(bbd)
    print 'has a radius of {:.2f}'.format(c.radius)
    print 'has an area of {:.2f}'.format(c.area())
示例#3
0
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
## perimeter() and infer the instance data indirectly.

## ISO 10667:  No circle software shall store the radius.
## It MUST store the diameter and ONLY the diameter.
示例#4
0
m = MonsterTire(30)
print 'A monster tire with an inner radius of', m.radius
print 'has an inner area of', m.area()
print 'and an outer perimeter of', m.perimeter()
print

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

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

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

c = Circle.from_bbd(25)
print 'A circle with a bounding box diagonal of 25'
print 'has a radius of', c.radius
print 'a perimeter of', c.perimeter()
print 'and an area of', c.area()
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.

# ISO 10667: No circle software shall store the radius in an instance.
# It MUST store the diameter and ONLY the diameter.

示例#5
0
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


# Customer 6: The Feds
# We like to micromanage
# We'll tell you not just WHAT to build but also
# How to build it
# It should not directly access the radius inside inside area methods

# Area methods must infer the radius from the circumference
# Circle instances must not store the radius
# A circle instance must store the diameter and ONLY the the diameter
示例#6
0
文件: client.py 项目: vish1/code
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.
# It MUST call perimeter() and infer the radius indirectly

# ISO 10112: No circle software shall store the radius. It must store the diameter and only the diameter.

示例#7
0
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

# ISO-10666-fake
# Thou shalt not create area methods that directly access the radius
# Instead you must infer the radius from the perimeter

# ISO-10667
# Circle classes must not store the radius