TypeError: unsupported operand type(s) for /: 'NoneType' and'NoneType'

J

Jordan Harry

I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it:

def factorial(n):
a = n
b = n
while a>0 and b>1:
n = (n)*(b-1)
b = b-1

def perm(n, r):
a = factorial(n)
b = factorial(n-r)
q = a / b
print q

Then I went back to IDLE and input the following:

I recieved the following error message:

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
mod.perm(5, 4)
File "C:\Python25\mod.py", line 27, in perm
q = a / b
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'

I have no idea how to fix it. I'm pretty new to Python. I have IDLE 1.2.2 and Python 2.5.2,

Please help.
 
S

Sean DiZazzo

I'm trying to write a simple program to calculate permutations.  I created a file called "mod.py" and put the following in it:

def factorial(n):
    a = n
    b = n
    while a>0 and b>1:
        n = (n)*(b-1)
        b = b-1

def perm(n, r):
    a = factorial(n)
    b = factorial(n-r)
    q = a / b
    print q

Then I went back to IDLE and input the following:


I recieved the following error message:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    mod.perm(5, 4)
  File "C:\Python25\mod.py", line 27, in perm
    q = a / b
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'

I have no idea how to fix it.  I'm pretty new to Python.  I have IDLE 1.2.2 and Python 2.5.2,

Please help.

Your factorial function needs to return something.

~Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,044
Messages
2,570,388
Members
47,052
Latest member
ketan

Latest Threads

Top