I'm doing review questions to prepare for my first exam and ran into an issue here. The question asks to use a multiway if statement to assign a value to y for y=f(x) for specific regions. The python shell keeps returning 'invalid syntax' and highlights the y in the third print command. When I delete the final 'elif' statement and 'else' statement I am able to run the program, so I'm guessing there is an issue with one of those?
x=float(input("Enter a value for x."))
if x<=0.0:
y=0.0
print("y =", y)
elif x>0.0 and x<=1.0:
y=x**2
print("y =", y)
elif x>1.0 and x<=10.0:
y=1.0
print("y =," y)
else:
y=0.0
print("y =", y)
Aucun commentaire:
Enregistrer un commentaire