复习了一元二次方程组,现在好想回去把5年高考3年模拟翻开做做,呵呵
Topic source# -*- coding: utf-8 -*-
import math
def quadratic(a,b,c):
x1 = (-b + math.sqrt(b**2 - 4*a*c))/2*a;
x2 = (-b - math.sqrt(b**2 - 4*a*c))/2*a;
return x1,x2
print(quadratic(2, 3, 1)) # => (-0.5, -1.0)
print(quadratic(1, 3, -4)) # => (1.0, -4.0)
# -*- coding: utf-8 -*-
import math
def quadratic(a,b,c):
if not (isinstance(a, int) and isinstance(b, int) and isinstance(c, int)):
raise TypeError('bad operand type')
x1 = (-b + math.sqrt(b**2 - 4*a*c))/2*a
x2 = (-b - math.sqrt(b**2 - 4*a*c))/2*a
return x1,x2
print(quadratic(1, "b", 1)) # => (-0.5, -1.0)
print(quadratic(1, 3, -4)) # => (1.0, -4.0)
#一个简单的,乘以2的函数,为什么算不出来呀,求教哪里错了。
import math def q(a,b): x=2a y=2b return x,y print(q(3,5)) SyntaxError: invalid syntax
- 1
可可豆公子
-- coding: utf-8 --
import math def quadratic(a,b,c): x1 = (-b + math.sqrt(b2 - 4ac))/2*a; x2 = (-b - math.sqrt(b2 - 4ac))/2*a; return x1,x2
print(quadratic(2, 3, 1)) # => (-0.5, -1.0) print(quadratic(1, 3, -4)) # => (1.0, -4.0)