[PLUG] Novice Python Error #6
Rich Shepard
rshepard at appl-ecosys.com
Wed Jul 13 00:40:41 UTC 2005
I get the same error with this code whether I run it interactively or at
the command line:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "combos.py", line 17
num = factorial.factorial(m)
^
SyntaxError: invalid syntax
I don't know why the syntax is invalid.
The files factorial.py and combos.py are attached. Factorial works from
both the command line and interactively. The name of the variable is
immaterial; 'top' or 'foo' produce the same error.
Rich
--
Dr. Richard B. Shepard, President | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
-------------- next part --------------
#!/usr/bin/python
def factorial(n):
if int(n == 0):
return 1
else:
return n * factorial(n-1)
if __name__ == '__main__':
import sys
n = int(sys.argv[1])
print n * factorial(n-1)
-------------- next part --------------
#!/usr/bin/python
"""
Calculates the number of combinations of 'm' things taken 'n' at a time.
"""
import factorial
def combos(m, n):
num = factorial.factorial(m)
denom = factorial.factorial(n) * factorial.factorial(m-n)
c = num / denom
return c
if '__name__' == '__main__':
import sys, factorial
m = int(sys.argv[1])
n = int(sys.argv[2]
num = factorial.factorial(m)
denom = factorial.factorial(n) * factorial.factorial(m-n)
c = num / denom
print c
More information about the PLUG
mailing list