当我使用合成功能时如Collatz(MerrenianPrime(Number)) 我得到错误:
'Merrenian=2**PrimeCount(Number)-1
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'NoneType.'
我如何解决这个问题?
这是我的代码:
def MerrenianPrime(Number):
Merrenian=2**Prime.PrimeCount(Number)-1 #PrimeCount=nth Prime and this is where I get an error
if Prime.isPrime(Merrenian)==True: #isPrime function checks primality of number
print "the prime number",Merrenian,"was found"
else:
print Merrenian,"is not prime."
谢谢!
答案 0 :(得分:1)
Prime.PrimeCount()
可调用返回None
(通常是因为您没有包含return
语句。)
修复该方法以返回数值。