Zdefiniuj funkcję f(x), która zwraca wartość następującego wyrażania zdefiniowanej na całej osi liczbowej f(x) = 1 - (x + 2)^2, jeśli x <= -2, -(x/2), jeśli -2 < x < 2, (x - 2)^2 + 1, jeśli x > 2.
Moje rozwiązanie:
def f(x):
if x <= -2:
return 1 - ((x+2)(x+2))
elif -2 < x <= 2:
return -(x/2)
else x > 2:
return ((x-2)(x-2)) + 1
# put your python code here
Failed test #1 of 35. Runtime error
Traceback (most recent call last):
File "jailed_code", line 11, in <module>
print(f(test_x))
NameError: name 'f' is not defined
Dlaczego moje rozwiązanie nie działa prawidłowo?