[Tutor] Exercise in writing a python function.
Kermit Rose
kermit at polaris.net
Wed Aug 9 04:54:58 CEST 2006
Hello all.
I feel more familar with Python now, and when I recently went back to
reading
the tutorial, I could actually read it without being overwhelmed by too
much new detail.
I've been staring at the specs for a python function for a while.
I wrote one version of it and it worked.
Then I changed the specs, and now need to reconstruct my original work.
I'm sure I can do it fairly easily.
I'm not asking anyone to write the function for me.
It did occur to me that it could be a classroom exercise for other students.
The current specifications for the function are:
def incr(mult,z,zlim,mpylist):
# mult is a vector of exponents for the multipliers in mpylist.
# z is a positive odd integer.
# zlim is the upper bound critical value for the sum of ( mpylist[k][0] *
mpylist[k][1] )
# where kth multiplier is mpylist [k][0]
# and kth multiplier index is mpylist [k][1]
# function incr returns the next value of vector mult.
# mult may be thought as a number written in a variable base.
# mult[0] is the least significant and matches multiplier mpylist[0][0]
# adding one to mult would mean adding 1 to mult[0]
# unless doing so would make sum of multiplier * index exceed zlim.
# in that case mult[0] is set to zero, and 1 is added to mult[1]
# unless doing so would make sum of multilier * index exceed zlim
# in that case, mult[0] and mult[1] is set to zero,
# and 1 is added to mult[2]
# unless . . .
# mult[0] is set to -1 to indicate that the largest possible value of mult
has been exceeded.
# mpylist[0][0] = 2 and all other multipliers in mpylist are odd.
# mult[0], the index on multiplier 2, must not equal 1. It may equal zero,
or any integer > 1,
# provided the zlim constraint is met.
More information about the Tutor
mailing list