Speaking Python

Andrew Dalke adalke at mindspring.com
Mon Oct 13 20:54:56 EDT 2003


David Mertz:
> So quick test, how do you say:
>
>     def range_sum(N):
>         if N < 0:
>             return None
>         elif N == 1:
>             return 1
>         else:
>             tot = 0
>             for n in range(1,N+1):
>                 tot += n
>             return tot

Here's how I would say it to someone who is typing
for me, given that the person knows some Python syntax
and given an editor which does auto indentation -- the
proverbial man-behind-the-curtains approach to speech
recognition:

Define a new function named range underscore sum which takes
a single parameter, capital N.

If n is less than 0, return none.
If n is 1, return 1
otherwise
start with tot equal to 0  (that's tee-oh-tee; short for the total)
for n, which is lowercase n this time, in range starting at 1 and
going to capital n plus 1 ... close-parens colon newline
tot plus equals lower-case n
backspace once
return tot

This depends on seeing the text as it's typed.  I think if I
did this over the phone I would say "if n equals equals 1" and
be a bit more specific about the colons and pressing enter.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list