Assignment 1.2 - Answer

# This is a program to calculate the solutions of the solution of the quadratic equation
print ("Welcome. This is a program to calculate the solutions of the")
print ("quadratic equation that has the from ax2+bx+c=0")
import math
a = float(input("Please write down number a different than zero. a = "))
b = float(input("Please write down number b = "))
c = float(input("Please write down number c = "))
print ()# print an empty line
if a==0:
    print ("You input zero to a, so i am exiting. Be more careful next time. Bye")
else:
    D = b**2 - 4*a*c  
    if D < 0 :
        print ("The equation dos not have real solutions")
    elif D == 0 :
        x = -b/(2*a)
        print ("The equation has one double solution x = ", x)
    else :
        x1 = (-b + math.sqrt(D))/(2*a)
        x2 = (-b - math.sqrt(D))/(2*a)
        print ("The equation has two solutions x1 = ", x1, " and x2 = ", x2)
input("Press enter to exit ;)")
 
Last modified: Friday, 12 May 2017, 12:02 AM