#!/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(b, (int, float)):
raise TypeError('bad operand type')
delta = b * b - 4 * a * c
if delta >= 0:
e = math.sqrt(delta)
m = (-b + e) / (2 * a)
n = (-b - e) / (2 * a)
print('The equation\'s roots are...\nx1 = %.1f , x2 = %.1f ...' % (m, n))
return m,n
else:
print('There is no root...')
pass
print('please enter the a, b, c of the equation: ax2 + bx + c = 0')
t1 = float(input('a = ',))
t2 = float(input('b = ',))
t3 = float(input('c = ',))
r = quadratic(t1, t2, t3)
最后一行,用 r = ,如果方程没有解,就运行正常,
如果写成 x1,x2 = , 如果方程没有解,就NoneType object is not iterable ...
求解释...
言語就像風WordsAreWind
最后一行,用 r = ,如果方程没有解,就运行正常, 如果写成 x1,x2 = , 如果方程没有解,就NoneType object is not iterable ... 求解释...