As an exercise that I thought would help me understand the decimal 
module, I've been trying write a script (precisionFactorial.py) that 
uses a modified fact(n) to compute precise factorials using the 
decimal module. I''m getting nowhere fast, and don't understand why. 
Here's what I have so far:

def fact(n):
     """
     compute n!
     """
     product = 1
     while n > 1:
       product *= n
       n -= 1
     return product

========================================
# precisionFactorial.py

import decimal

def d(x):
     return decimal.Decimal(str(x))

def fact(n):
     product = 1
     while d(n) > 1:
         product *= n
         d(n) -= 1
     return product

n = 100
decimal.getcontext().prec = 200
print product
===================================

This gets me

"Syntax error
Theres an error in your program.
*** can't assign to function call
(precisionFactorial.py, line 11)"

line 11 is "d(n) -= 1".

Advice, please.

Dick Moores
[EMAIL PROTECTED]

Win XP, Python 2.4





_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to