Ejemplo n.º 1
0
def test_set_area():
    c = Circle(10)
    with pytest.raises(AttributeError):
        c.area = 100
Ejemplo n.º 2
0
p1 = Person('Hans Petter Langtangen',
            office_phone='67828283', email='*****@*****.**')
p2 = Person('Aslak Tveito', office_phone='67828282')
p2.add_email('*****@*****.**')
phone_book = [p1, p2]                             # list
for person in phone_book:
    person.dump()

phone_book = {'Langtangen': p1, 'Tveito': p2}     # dict is better
for person in sorted(phone_book):
    phone_book[person].dump()

from classes import Circle
c = Circle(2, -1, 5)
print 'A circle with radius %g at (%g, %g) has area %g' % \
      (c.R, c.x0, c.y0, c.area())

from classes import Derivative
from math import *
df = Derivative(sin)
print dir(df)
x = pi
df(x)
cos(x)  # exact
def g(t):
    return t**3

dg = Derivative(g)
t = 1
dg(t)  # compare with 3 (exact)
Ejemplo n.º 3
0
            office_phone='67828283',
            email='*****@*****.**')
p2 = Person('Aslak Tveito', office_phone='67828282')
p2.add_email('*****@*****.**')
phone_book = [p1, p2]  # list
for person in phone_book:
    person.dump()

phone_book = {'Langtangen': p1, 'Tveito': p2}  # dict is better
for person in sorted(phone_book):
    phone_book[person].dump()

from classes import Circle
c = Circle(2, -1, 5)
print 'A circle with radius %g at (%g, %g) has area %g' % \
      (c.R, c.x0, c.y0, c.area())

from classes import Derivative
from math import *
df = Derivative(sin)
print dir(df)
x = pi
df(x)
cos(x)  # exact


def g(t):
    return t**3


dg = Derivative(g)
Ejemplo n.º 4
0
from classes import Circle

circle1 = Circle(1,2,3)

print(circle1.perimeter())
print(circle1.area())

from classes import Tringle

tringle1 = Tringle(1,2,3)

print(tringle1.perimeter())
print(tringle1.area())

from classes import Square

square1 = Square(1,2)

print(square1.perimeter())
print(square1.area())