g

© All Rights Reserved

2 views

g

© All Rights Reserved

- 262585680 Abe Cofnas Sentiment Indicators Renko Price Break Kagi Point and Figure 2010 292 Pages.85
- 262585680 Abe Cofnas Sentiment Indicators Renko Price Break Kagi Point and Figure 2010 292 Pages.1
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..131
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..166
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..121
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..127
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..233
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..200
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..257
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..312
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..11
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..302
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..189
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..149
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..192
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..270
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..310
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..311
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..315
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..181

You are on page 1of 1

4.2

Specifications

Figure 4.5 defines a function, findRoot, that generalizes the bisection search we

used to find square roots in Figure 4.1. It also contains a function,

testFindRoot, that can be used to test whether or not findRoot works as

intended.

The function testFindRoot is almost as long as findRoot itself. To inexperienced

programmers, writing test functions such as this often seems to be a waste of

effort. Experienced programmers know, however, that an investment in writing

testing code often pays big dividends. It certainly beats typing test cases into

the shell over and over again during debugging (the process of finding out why a

program does not work, and then fixing it). It also forces us to think about

which tests are likely to be most illuminating.

The text between the triple quotation marks is called a docstring in Python. By

convention, Python programmers use docstrings to provide specifications of

functions. These docstrings can be accessed using the built-in function help.

If we enter the shell and type help(abs), the system will display

Help on built-in function abs in module __builtin__:

abs(...)

abs(number) -> number

Return the absolute value of the argument.

If the code in Figure 4.5 (below) has been loaded into IDLE, typing

help(findRoot) in the shell will display

Help on function findRoot in module __main__:

findRoot(x, power, epsilon)

Assumes x and epsilon int or float, power an int,

epsilon > 0 & power >= 1

Returns float y such that y**power is within epsilon of x.

If such a float does not exist, it returns None

If we type

findRoot(

in either the shell or the editor, the list of formal parameters and the first line of

the docstring will be displayed.

41

- 262585680 Abe Cofnas Sentiment Indicators Renko Price Break Kagi Point and Figure 2010 292 Pages.85Uploaded byZhichaoWang
- 262585680 Abe Cofnas Sentiment Indicators Renko Price Break Kagi Point and Figure 2010 292 Pages.1Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..131Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..166Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..121Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..127Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..233Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..200Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..257Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..312Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..11Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..302Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..189Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..149Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..192Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..270Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..310Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..311Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..315Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..181Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..162Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..123Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..223Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..293Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..160Uploaded byZhichaoWang
- Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..126Uploaded byZhichaoWang