Discuss / Python / 练练手

练练手

Topic source

草莓Z葵

#1 Created at ... [Delete] [Delete and Lock User]

#!/usr/bin/env python3

-- coding: utf-8 --

import math

def quadratic(a, b, c):
if not isinstance(a, (int, float)): raise TypeError('bad operand type') if not isinstance(b, (int, float)): raise TypeError('bad operand type') if not isinstance(c, (int, float)): raise TypeError('bad operand type') sqrt = b b - 4 a c if a == 0: return -b / c if sqrt < 0: return "无实数解" else: x1 = (-b + math.sqrt(sqrt)) / 2 a x2 = (-b - math.sqrt(sqrt)) / 2 * a return x1, x2


  • 1

Reply