def circle_area_microservice():
    try:
        radius = float(request.query.get('radius', '0.0'))
    except ValueError:
        radius = 0.0
    area = algebra.area(radius)
    return dict(service=request.path, radius=radius, area=area)
Пример #2
0
def circle_area_service():
    response.set_header('Cache-Control', 'max-age=15')
    try:
        radius = float(request.query.get('radius', '0.0'))
    except ValueError:
        return dict(error='Must supply a floating point radius')
    area = algebra.area(radius)
    return dict(area=area, radius=radius, service=request.path)
Пример #3
0
    except RuntimeError:
        raise ValueError('Negative base or height not supported, use positive inputs instead')

algebra.area_triangle = better_area_triangle              # Step 3:  Monkey patch

orig_sqrt = math.sqrt                                     # Step 1:  Save reference to original

def better_sqrt(x):                                       # Step 2:  Write a wrapper function
    'Wraps math.sqrt to add support for negative inputs'
    if x >= 0.0:
        return orig_sqrt(x)
    return orig_sqrt(-x) * 1j

math.sqrt = better_sqrt                                   # Step 3:  Monkey patch

#############################################################################

if __name__ == '__main__':

    print u'My sources tell me that \N{greek small letter pi} =', algebra.pi
    print 'and that the area of a circle of radius ten is:', algebra.area(10)
    print 'The area of the 1st triangle is', algebra.area_triangle(base=25, height=10)
    try:
        print 'The area of the 2nd triangle is', algebra.area_triangle(base=-5, height=20)
    except ValueError:
        print '... oops, I did it again!'
    print u'The solutions to 12x\N{superscript two} + 23x + 10 = 0 are:'
    print algebra.quadratic(a=12, b=23, c=10)
    print u'The solutions to 12x\N{superscript two} + 8x + 10 = 0 are:'
    print algebra.quadratic(a=12, b=8, c=10)
Пример #4
0
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 19 10:02:54 2018

@author: md1eeb
"""
import algebra as c

r = 5

print(c.area(r))
print(c.circumference(r))

from algebra import area
r = 5
print(area(r))

from algebra import quad as q

a = 1
b = 9
c = 6

print(q(a, b, c))

from algebra import largest

list1 = [4, 6, 2, 4, 8, 12, 7]

print(largest(list1))
""""""
Пример #5
0
        raise ValueError('negative base or height not supported')
	
algebra.area_triangle = better_area_triangle    # Step 3: monkey patch

orig_sqrt = math.sqrt                           # Step 1: Save the original function

def better_sqrt(x):                             # Step 2: Write a wrapper function
    "Wrap math.sqrt() to add support for negative values."
    if x >= 0.0:
        return orig_sqrt(x)
    else:
        return orig_sqrt(-x) * 1j

math.sqrt = better_sqrt                         # Step 3: Monkey patch

if __name__ == '__main__':
    print u'My sources tell me that \N{greek small letter pi} =', algebra.PI
    print 'and that the unit circle has area', algebra.area(1)

    print 'The area of the 1st triangle is', algebra.area_triangle(7, 5)
    try:
        print 'The area of the 2nd triangle is', algebra.area_triangle(-5, 10)
    except ValueError:
        print 'Doh! Sorry for the negative input'

    print u'The solutions to 12x\N{superscript two} + 23x + 10 = 0 are:'
    print algebra.quadratic(a=12, b=23, c=10)
    print u'The solutions to 12x\N{superscript two} + 8x + 10 = 0 are:'
    print algebra.quadratic(12, 8, 10)