python - While Trying to def: TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int' -


i using code in python 2.7 produce new number by:

def alg(n):     n=((n**2)-1)/4     return n     

and error message:

typeerror: unsupported operand type(s) ** or pow(): 'nonetype' , 'int' 

any great! thanks!

somehow, you're passing none when call function, what's happening:

alg(none) 

... n none inside function, causing error. in other words: problem not in function, it's in point you're calling it.

also word of warning - you're performing division between integers, better play safe , make sure @ least 1 of division's operands decimal, or else loose precision:

def alg(n):               # there's no need reassign n     return ((n**2)-1)/4.0 # notice .0 part @ end 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -