I tried the following code:(adsbygoogle = window.adsbygoogle || []).push({});

Basically, for all n and r from 1 to 100, it's supposed to print ##\binom{n}{r}##Code (Text):def factorial(n):

if (n == 0):

return 1

else:

return n*factorial(n-1)

def ncr(n,r):

return ((factorial(n))/(factorial(r)*factorial(n-r)))

number = 0

for n in range(100):

for r in range(100):

print ncr(n,r)

Unfortunately, running from the command line, I get:

Code (Text):Traceback (most recent call last):

File "Pythontest.py", line 14, in <module>

print ncr(n,r)

File "Pythontest.py", line 8, in ncr

return ((factorial(n))/(factorial(r)*factorial(n-r)))

File "Pythontest.py", line 5, in factorial

return n*factorial(n-1)

File "Pythontest.py", line 5, in factorial

return n*factorial(n-1)

File "Pythontest.py", line 5, in factorial

return n*factorial(n-1)

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# A bit of trouble with Python

**Physics Forums | Science Articles, Homework Help, Discussion**