r/pythonhelp • u/Erdii7 • Sep 06 '22
Function with multiple x
Hey I'm totally new to programming and I struggle with this task, so if anyone could help me out that would mean a lot.
Write a program that can calculate values of f (x) for the following function:
f(x)=x^-0.2, 0 < x <= 1, when x = (-0.4, 0.0, 0.4, 0.8, 1.2)
I tried this: but got the error "ZeroDivisionError: 0.0 cannot be raised to a negative power":
values=[-0.4, 0.0, 0.4, 0.8, 1.2]
for x in values:
y = x**(-2)
if(x > 0 and x < 1):
print(y)
0
Upvotes
1
u/AmongstYou666 Sep 06 '22
def f(x):answer = []for i in x:if i > 0 and i < 1:answer.append(i**-0.2)else:answer.append(None)return(answer)print(f([-0.4, 0.0, 0.4, 0.8, 1.2]))