EXPLAIN THE PYTHON CODE EXAMPLES HERE:
Simple code of real roots of a quadratic equation entering a, b and c values:
# Finding the roots of a quadratic equation
a = float(input("Enter A: "))
b = float(input("Enter B: "))
c = float(input("Enter C: "))
d = b**2 - 4*a*c
r1 = (-b + d**0.5)/(2*a)
r2 = (-b - d**0.5)/(2*a)
print("The roots are", r1, "and", r2)
Quadratic equation with assigned values a, b and c and complex numbers
#Python program to find roots of quadratic equation
import math
# function for finding roots
def equationroots( a, b, c):
# calculating discriminant using formula
dis = b * b - 4 * a * c
sqrt_val = math.sqrt(abs(dis))
# checking condition for discriminant
if dis > 0:
print(" real and different roots ")
print((-b + sqrt_val)/(2 * a))
print((-b - sqrt_val)/(2 * a))
elif dis == 0:
print(" real and same roots")
print(-b / (2 * a))
# when discriminant is less than 0
else:
print("Complex Roots")
print(- b / (2 * a), " + i", sqrt_val)
print(- b / (2 * a), " - i", sqrt_val)
# Driver Program
a = 1
b = 10
c = -24
# If a is 0, then incorrect equation
if a == 0:
print("Input correct quadratic equation")
else:
equationroots(a, b, c)
In this trinket below you can find the two previous python codes remixed in order to obtain a, b and c data from user and complex roots are also obtained
Find a better solution for quadratic equation and solve mathematical problems regarding Technology
Using IDLE included python editor with tkinter packages as an interface to read colour code of resistors