SharedPolyRtFinder.sagewsOpen in CoCalc
# How to evalutate the roots of second degree polymomials
# Programming language used: Python
# Example of polynomials utility: solving real world problems by establishing a profit function constraints, that profit function will be studied in order to maximize a company's profit
# Excecute the program by pressing the buttons "Shift + Enter" or by Using Python 3.6.0 Shell (a better ground for excecuting Python codes)

import math
import sys
print("Hello!")
print("Your second degree polynomial will be the form: a X^2+ b X+ c =0")
a = float(input("Enter a: "))
b = float(input("Enter b: "))
c = float(input("Enter c: "))
#Discriminant method also known as delta method
Delta = b*b-(4*a*c)
if Delta < 0:
print("The solutions are complexe numbers")
sys.exit()
sqrtDelta = math.sqrt(Delta)
if Delta > 0:
root1 = (-b+sqrtDelta)/2*a
root2 = (-b-sqrtDelta)/2*a
print("The solutions are: Root 1 = " + str (root1) + " and Root 2 = " + str(root2))
elif Delta == 0:
root = -b/2*a
print("The double solution is:" + str (root))

Hello! Your second degree polynomial will be the form: a X^2+ b X+ c =0
Enter a:
Enter b:
Enter c:
The solutions are: Root 1 = -0.585786437627 and Root 2 = -3.41421356237