# Problem with Python, I get this error: 'NoneType' and 'NoneType'

3

Good morning, I have this code and it turns out that I get this error when I compile

Traceback (most recent call last): File "questionnaire__5.py", line   25, in       aa = (a) / (b) TypeError: unsupported operand type (s) for /: 'NoneType' and 'NoneType'

``````def myfun(x):
np.cos(x)/(1+(np.sin(x))**2)
a=myfun(np.pi/3)
b=myfun(np.pi/6)
aa=(a)/(b)
print(aa)
``````

Do you know what is happening?

asked by Fran Ahedo Guerrero 31.07.2017 в 13:24
source

3

Put correctly the imports and make a return at the end.

``````import math
import numpy as np
import scipy

def myfun(x):
num = np.cos(x)/(1+(np.sin(x))**2)
return num

a=myfun(np.pi/3)
b=myfun(np.pi/6)
aa=(a)/(b)

print(aa)
``````

source
0

Here are two ways:

``````import numpy as np
def myfun(x):
return np.cos(x)/(1+(np.sin(x))**2)

# Segundo Modo: lambda function
myfun = lambda x: np.cos(x)/(1+(np.sin(x))**2)
``````

Use

``````a=myfun(np.pi/3)
b=myfun(np.pi/6)
aa=(a)/(b)

print(aa)
``````