daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Oct 17th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. from math import sqrt
  3.  
  4. print "Enter the numbers you would like to find quadratics for" #tests if variables are acquired correctly
  5.  
  6. a = input("Enter a: ") #variable declared by user input
  7. b = input("Enter b: ") #variable declared by user input
  8. c = input("Enter c: ") #variable declared by user input
  9.  
  10. equation = b * (b - 4.0) * a * c
  11.  
  12. if equation >= 0:  
  13.     root1 = (-b + math.sqrt(b ** 2 - 4 * a * c)) / 2
  14.     root2 = (-b + math.sqrt(b ** 2 - 4 * a * c)) / 2
  15.     print  "root 1: "  + root1
  16.     print  "root 2: "  + root2
  17.    
  18.            
  19. else:
  20.     rP = -b / (2.0 * a )
  21.     iP = math.sqrt(-equation)/(2.0 * a)
  22.     print "root1=" + rP + "+" + iP + "i"
  23.     print "root2= " + rP + "-" + iP + "i"
  24.  
  25. raw_input()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top