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

Ben Finney bignose+hates-spam at benfinney.id.au
Thu May 1 21:31:15 EDT 2008


"Jordan Harry" <jharry at EmeryWeiner.org> writes:

> 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

A function that does some calculations internally, but has no 'return'
statement and thus implicitly returns 'None'.

> def perm(n, r):
>     a = factorial(n)
>     b = factorial(n-r)

These statements bind the 'None' returned by the 'factorial' function
to the names 'a' and 'b'.

>     q = a / b

This attempts to use the '/' operator on 'None' with 'None', which
raises the exception you saw.

(good sigmonster, have a cookie)

-- 
 \         "Pinky, are you pondering what I'm pondering?" "I think so, |
  `\    Brain, but Zero Mostel times anything will still give you Zero |
_o__)                               Mostel."  -- _Pinky and The Brain_ |
Ben Finney



More information about the Python-list mailing list