# Assignment 1.2

## Assignment 1.2

**Opened:**Saturday, 6 May 2017, 12:00 AM

In mathematics there is an equation that is called quadratic. It is usually written in the form **ax ^{2}+bx+c=0**, where x represents an unknown, and a, b, and c represent known numbers such that a is not equal to 0.

Our goal is to write a program that outputs the solutions of the quadratic equation.

In order to solve the quadratic equation the easiest method is to calculate the discriminant.

If the discriminant is less than zero then the equation does not have real solution.

If the discriminant is equal to zero then the equation has one double real solution.

Finally if the discriminant is greater than zero then the equation has two different real solutions.

that we can calculate using the previous formulas.

So how can we calculate the square root of discriminator? Python has a library that we can use if we include it in the beginning of our code. The library is called **math **and has many useful functions. One of them is sqrt.

Try the following code

**import mathprint (math.sqrt(16))**

You can view all the functions inside math following** the link**

So a sample code to start could be :

```
# This is a program that calculates the solutions of an 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( ) # complete the command
c = # complete the command
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 = # complete the command
print ("The equation has one double solution x = ", x)
else :
x1 = (-b + math.sqrt(D))/(2*a)
x2 = # complete the command
print ("The equation has two solutions x1 = ", x1, " and x2 = ", x2)
```