Reputation: 15
Getting an ELIF syntax error, I'm new to python and i have no idea why I'm I getting this error
print("Résolution de l'équation du second degré : ax² + bx + c = 0")
chaineA= input("Coefficient de a ?: ")
a= float(chaineA)
chaineB= input("Coefficient de b ?: ")
b= float(chaineB)
chaineC= input("Coefficient de c ?: ")
c= float(chaineC)
delta=((b**2)-(4*a*b))
solut1= (-b + (delta**0.5)/(2*a))
solut2= (-b - (delta**0.5)/(2*a))
solut3= (-b/2*a)
if delta >= 0.0:
print("Deux solutions: ")
print("x1 =" , solut1)
print("x2 =" , solut2)
elif delta = 0.0:
print("Une solution")
print("x =" , solut3)
elif delta <= 0.0:
print("Pas de solution")
Thanks in advance
Upvotes: 0
Views: 211
Reputation: 127
By only using one = in your elif it thinks you are trying to assign 0.0 to delta. It should be:
elif delta == 0.0
This will compare delta to 0.0 and if they are the same run your code in the elif.
Upvotes: 1
Reputation: 2111
print("Résolution de l'équation du second degré : ax² + bx + c = 0")
chaineA= input("Coefficient de a ?: ")
a= float(chaineA)
chaineB= input("Coefficient de b ?: ")
b= float(chaineB)
chaineC= input("Coefficient de c ?: ")
c= float(chaineC)
delta=((b**2)-(4*a*b))
solut1= (-b + (delta**0.5)/(2*a))
solut2= (-b - (delta**0.5)/(2*a))
solut3= (-b/2*a)
if delta >= 0.0: # here it should be > only
print("Deux solutions: ")
print("x1 =" , solut1)
print("x2 =" , solut2)
elif delta = 0.0: # first error here it should be elif delta == 0:
print("Une solution")
print("x =" , solut3)
else: #this could be made else. no need to put a condition.
print("Pas de solution")
Upvotes: 0