5**2
Note that you should use the **
operator. ^
does something different:
5^2
We can of course use $x^{0.5}$ to compute square roots:
64**0.5
We can also use the following:
import math #has to be in the code before we use math.sqrt
math.sqrt(225)
Now, we are ready to begin writing the code:
import math
a = 1
b = 5
c = 2
disc = b**2-4*a*c
if disc > 0:
r1 = (-b + math.sqrt(disc))/(2*a)
r2 = (-b - math.sqrt(disc))/(2*a)
elif disc == 0:
r = (-b + math.sqrt(disc))/(2*a)
else:
print("There are no real solutions")