Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from math import sqrt as normalny
  2. from cmath import sqrt as zespolony
  3.  
  4. a: int = 5
  5. b: int = 9
  6. c: int = 1
  7.  
  8. def rownaniekwadratowe(a, b, c):
  9.  
  10.  
  11.     delta = (b**2)-4*(a*c)
  12.     print(delta)
  13.    
  14.    
  15.     if delta > 0:
  16.         return rzeczywiste(a, b, delta)
  17.     else:
  18.         if delta < 0:
  19.             return zespolone(a, b, delta)
  20.         else:
  21.             return jednorozwiazanie(a, b)
  22.  
  23.  
  24. def rzeczywiste (a, b, delta) :
  25.  
  26.  
  27.         delta = normalny(delta)
  28.         x1 = (-b-delta)/(2*a)
  29.         x2 = (-b+delta)/(2*a)
  30.         print("pierwsiastki rzeczywiste :")
  31.         return ( x1 , x2 )
  32.  
  33. def  jednorozwiazanie ( a, b):
  34.          x1 = (-b)/(2*a)
  35.          print("pierwiastek rzeczywisty : ")
  36.          return ( x1 )
  37.  
  38. def zespolone(a,b,delta) :
  39.         delta = complex(delta, 0)
  40.         delta = zespolony(delta)
  41.         x1 = (-b - delta) / (2 * a)
  42.         x2 = (-b + delta) / (2 * a)
  43.         print("Pierwiastki zespolone: ")
  44.         return(x1,x2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement