#!/usr/bin/env python # # Author: Yotam Medini yotam.medini@gmail.com -- Created: 2006/June/01 # # print_root Version 2 - demonstarting function with default values # import sys # Version 2.0 def print_root(a, order=2): low = 0. high = a + 1. progress = True while progress: mid = (low + high) / 2. progress = (low < mid < high); # if mid**order < a: low = mid else: high = mid sys.stdout.write("root(%4g) = %f\n" % (a, mid)) # Demo Application def application1(): sys.stdout.write("\nApplication-1:\n") for n in range(0, 11): print_root(n) # Demo Application def application2(): sys.stdout.write("\nApplication-2:\n") for order in [2, 3]: sys.stdout.write("\nRoots of order=%d\n" % order) for n in range(0, 10): print_root(n, order) # Main program application1() application2() sys.exit(0)