Speaking Python

Sean Ross sross at connectmail.carleton.ca
Mon Oct 13 17:14:16 EDT 2003


"David Mertz" <mertz at gnosis.cx> wrote in message
news:mailman.72.1066076254.2192.python-list at python.org...
> 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

def range underscore sum open bracket n close bracket colon new line indent
if n less than zero colon newline indent
return none newline dedent
elif n equals equals 1 colon newline indent
return 1 newline dedent
else colon newline indent
tot equal zero newline
for n in range open bracket 1 comma n plus 1 close bracket colon newline
indent
tot plus equal n newline dedent
return tot newline dedent
dedent

(this assumes that the user is aware that if no indent or dedent message is
given, the current level of indentation should be maintained).






More information about the Python-list mailing list