Solving quadratic equations using Python | Easy Solution

preview_player
Показать описание
Hey Guys! In this video, you will learn how to solve quadratic equations using python. In this program, we are utilizing regular expressions and functions. Please like and subscribe!

Sample code (paste this into your text editor and save it as a .py file):

import re

def sqrt(intg):
return intg ** 0.5

def quadratic_formula1 (a, b, c):
delta = b**2 - 4*a*c
numerator = -b + sqrt(delta)
denominator = 2*a
root1 = numerator/denominator
return root1

def quadratic_formula2 (j, k, l):
delta2 = k**2 - 4*j*l
numerator2 = -k - sqrt(delta2)
denominator2 = 2*j
root2 = numerator2/denominator2
return root2

equation = input('Please enter the equation in the following format: \nax^2 + bx + c = 0: \n')
quadratic_coefficient = int(numbers[0])
linear_coefficient = int(numbers[2])
constant = int(numbers[3])
result1 = quadratic_formula1(quadratic_coefficient, linear_coefficient, constant)
result2 = quadratic_formula2(quadratic_coefficient, linear_coefficient, constant)
print('\nThe results are: ', '\nx1 = ', result1, ' ', 'x2 = ', result2)
Рекомендации по теме
Комментарии
Автор

Comment to see what codes you want me to do!

deathunter