Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from math import sqrt
- print "Enter the numbers you would like to find quadratics for" #tests if variables are acquired correctly
- a = input("Enter a: ") #variable declared by user input
- b = input("Enter b: ") #variable declared by user input
- c = input("Enter c: ") #variable declared by user input
- equation = b * (b - 4.0) * a * c
- if equation >= 0:
- root1 = (-b + math.sqrt(b ** 2 - 4 * a * c)) / 2
- root2 = (-b + math.sqrt(b ** 2 - 4 * a * c)) / 2
- print "root 1: " + root1
- print "root 2: " + root2
- else:
- rP = -b / (2.0 * a )
- iP = math.sqrt(-equation)/(2.0 * a)
- print "root1=" + rP + "+" + iP + "i"
- print "root2= " + rP + "-" + iP + "i"
- raw_input()
Add Comment
Please, Sign In to add comment