Python goes well with math, you know!
So... how do you solve an equation of second degree?
So... how do you solve an equation of second degree?
from math import sqrt
x1=0
x2=0
def solve(a=0,b=0,c=0):
global x1,x2
'solve the equation'
delta = (b**2)-(4*a*c)
print("Delta=",delta)
if delta < 0:
print("There are no solutions, delta is negative")
x1 = 'Nan'
x2= 'Nan'
else:
x1 = (-b+sqrt(delta))/(2*a)
x2 = (-b-sqrt(delta))/(2*a)
return x1,x2
solve(2,-5,-3) # Change the parameters here
print("\nx1 =",x1,"\n\nx2 =",x2)
Comments
Post a Comment