Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt as rad
- def sign(x):
- if x > 0: return 1.
- if x < 0: return -1.
- if x == 0: return 0.
- def getnr(name):
- r = input(name + "=")
- t = str(type(r))
- if t == "<type 'int'>" or t == "<type 'float'>":
- return float(r)
- while t != "<type 'int'>" and t != "<type 'float'>":
- print("singur int sau float");
- r = input (name + "=");
- t = str(type(r));
- if t == "<type 'int'>" or t == "<type 'float'>":
- return float(r)
- def getComplex(name):
- r = input(name + "=")
- t = str(type(r))
- if t == "<type 'int'>" or t == "<type 'float'>" or t == "<type 'complex'>":
- return complex(r)
- while t != "<type 'int'>" and t != "<type 'int'>" and t != "<type 'complex'>"
- print "complex"
- r = input(name + "=")
- t = str(type(r))
- if t == "<type 'int'>" or t == "<type 'float'>" or t == "<type 'complex'>":
- return complex(r)
- def ecgrad2():
- print "Ecuatia de gradul 2"
- a = getnr('a')
- b = getnr('b')
- c = getnr('c')
- delta = b * b - 4 * a * c
- if a == 0:
- print "Ecuatie de gradul 1"
- return
- if delta == 0:
- print str(-b/(2*a))
- return
- if delta > 0:
- x1 = -b + rad(delta) / 2 * a
- x2 = -b - rad(delta) / 2 * a
- print str(x1)
- print str(x2)
- return
- if delta < 0:
- x1 = complex(-b, -rad(-delta))/ (2*a)
- print str(x1)
- x2 = complex(-b, rad(-delta)) / (2*a)
- print str(x2)
- return
- print(sign(-2))
- ecgrad2();
Advertisement
Add Comment
Please, Sign In to add comment