Пример #1
0
# 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.

# ISO-12346
# Circle instances must not store the radius.
# A circle instance must store the diameter
# and ONLY the diameter.

print 'government inspection'
c = Circle(10)
print c.__dict__
print c.radius
print c.area()
c.radius = 20
print c.__dict__
Пример #2
0
"Show-off the Circuitous code from the user's point of view"

from __future__ import division
from circuitous import Circle

print u'Tutorial from Circuitous\N{trade mark sign}'
print 'Circle class version %d.%d' % Circle.version[:2]
c = Circle(10)
print 'A circle with a radius of', c.radius
print 'has an area of', c.area()
print

## Academia ################################################

from random import seed, random
from pprint import pprint

n = 10000
jenny = 8675309
seed(jenny)
print 'DARPA Grant Proposal to study the average area of random circles'
print 'using Circuitous(tm) version %d.%d' % Circle.version[:2]
print 'preliminary study of {n} random circles'.format(n=n)
print "seed with Jenny's number: {jenny}".format(jenny=jenny)
circles = [Circle(random()) for i in xrange(n)]
areas = [circle.area() for circle in circles]
average_area = sum(areas) / n
print 'The average area is %.5f' % average_area
print

## Rubber Sheet Company ####################################
Пример #3
0
"Show-off the ciruitous code from the user's point of view"

from __future__ import division
from circuitous import Circle

print u'Tutorial for Circuitous\N{trade mark sign}'
print 'Circle version %d.%d' % Circle.version[:2]
c = Circle(10)
print 'A circle with a radius of', c.radius
print 'has an area of', c.area()
print

## Academic Friends ######################################

from random import seed, random
from pprint import pprint

n = 100000
jenny = 8675309
print 'DARPA Grant Proposal'
print 'to study the average area of random circles'
print 'using Circuitous(tm) version %d.%d' % Circle.version[:2]
print 'preliminary study using %d random circles' % n
print "seeded using Jenny's number: %d" % jenny
seed(jenny)
circles = [Circle(random()) for i in xrange(n)]
areas = [circle.area() for circle in circles]
average_area = sum(areas) / n
print 'The average area is %.5f' % average_area
print
Пример #4
0
from __future__ import division
from circuitous import Circle

c = Circle(10)
print u'Tutorial for Circuitous\N{trade mark sign}'
print 'Version %d.%d'% Circle.version
print 'A circle with a radius of', c.radius
print 'has an area of', c.area()
print


## Academic Friends ####

from random import random, seed
from pprint import pprint

jenny = 8675309
n = 10
print 'DARPA Grant Proposal to compute the average area of random circles'
print 'Proof of concept with %d randomly chosen circles' % n
print "Seeded with Jenny's number:", jenny
seed(jenny)
circles = [Circle(random()) for i in xrange(n)]
areas = [c.area() for c in circles]
average_area = sum(areas) / n
print 'The average area is %.1f' % average_area
print

## Rubber Sheet #######

print 'Rubber sheet cut template spec sheet'
Пример #5
0
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
# Circle classes must store the diameter and ONLY the diameter

print 'federal inspection'
c = Circle(10)
print c.__dict__
print c.area()
c.radius = 20
print c.__dict__
Пример #6
0
"Show-off the ciruitous code from the user's point of view"

from __future__ import division
from circuitous import Circle
import math

print u'Tutorial for Circuitous\N{trade mark sign}'
print 'Circle version %d.%d' % Circle.version[:2]
c = Circle(10)
print 'A circle with a radius of', c.radius
print 'has an area of', c.area()
print

## Academic Friends ######################################

from random import seed, random
from pprint import pprint

n = 10
jenny = 8675309
print 'DARPA Grant Proposal'
print 'to study the average area of random circles'
print 'using Circuitous(tm) version %d.%d' % Circle.version[:2]
print 'preliminary study using %d random circles' % n
print "seeded using Jenny's number: %d" % jenny
seed(jenny)
circles = [Circle(random()) for i in xrange(n)]
areas = [circle.area() for circle in circles]
average_area = sum(areas) / n
print 'The average area is %.1f' % average_area