Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. from math import sqrt
  2. imp=open('import.txt','r')
  3. out=open('outport.txt','w')
  4.  
  5. line= imp.readline()
  6. spline= line.split()
  7.  
  8. q=float(spline[0])
  9. r=float(spline[1])
  10. t=float(spline[2])
  11. def quadr(a,b,c):
  12. d=0
  13. d=b*b-4*a*c
  14. if d>0:
  15. x1=(-b+sqrt(d))/(2*a)
  16. x2=(-b-sqrt(d))/(2*a)
  17. return (x1,x2)
  18. elif d==0:
  19. x1=-b/(2*a)
  20. return(x1,)
  21. else:
  22. return()
  23. solution=quadr(q,r,t)
  24. outline="error"
  25. print type(solution)
  26. if len(solution) == 0:
  27. outline="no solution"
  28. print outline
  29. out.write(outline)
  30. elif len(solution) == 1:
  31. outline="1 solution"
  32. x1=solution[0]
  33. #outline=' x1=%.5f\n' % (x1,)
  34. print x1
  35. print outline
  36. out.write(outline)
  37. else :
  38. outline="2 solution"
  39. x1=solution[0]
  40. x2=solution[1]
  41. print x1,x2
  42. print outline
  43. out.write(outline)
  44. imp.close()
  45. out.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement