I am trying to convert a float which has an integer value into a int, so it doesn't look like e.g 5.0.
#Quadratic calculator
import math
def is_int(x):
x = float(x)
if x.is_integer():
a = int(x)
return a
else:
pass
print("Quadratic Equation: ax^2 + bx + c = 0" )
a = float(input("a: "))
b = float(input("b: "))
c = float(input("c: "))
if a.is_integer():
a = int(a)
else:
pass
is_int(b)
print(str(a)+"x + "+str(b)+"x + "+ str(c)+ " = 0")
result=[]
result.append(-b+((b**2)-(4*a*c)**0.5)/(2*a))
result.append(-b-((b**2)-(4*a*c)**0.5)/(2*a))
print("x: " + str(result[0]) + " or " + "x: " + str(result[1]))
The result is:
Quadratic Equation: ax^2 + bx + c = 0
a: 2
b: 5
c: 1
2x + 5.0x + 1.0 = 0
x: 0.5428932188134521 or x: -10.542893218813452
Is there another way of doing this?