2019-05-23 14:05:02 Python

Python

Copy Copied! Full
import numpy as np def calculateQuadraticFormula(a, b, c): root = b * b - 4 * a * c if root < 0: root = np.sqrt(-root) / (2 * a) return [complex(- b / (2 * a), root), complex(- b / (2 * a), - root)] return [(- b + root) / 2 * a, (- b - root) / 2 * a] def printAnswer(ans): for i in range(0, len(ans)): print("x", (i+1), "=", '{:.3f}'.format(ans[i])) print("np.roots()の答え") printAnswer(np.roots([3, 5, 7])) print("二次方程式の解の公式の答え") printAnswer(calculateQuadraticFormula(3, 5, 7))
RECOMMEND