有点超纲吧
Topic sourceTraceback (most recent call last):
File "/Users/tieban/Documents/Python/一元二次方程.py", line 31, in <module>
print(quadratic())
File "/Users/tieban/Documents/Python/一元二次方程.py", line 28, in quadratic
q1 = ((-b + math.sqet(b**2-a*c*4))/(a*2))
AttributeError: module 'math' has no attribute 'sqet'
这是怎么回事呢?请问
- 1
飞页快刀
import math
def quadratic():
while True:
try:
a = float(input('请输入a: '))
na = float(a)
break
except:
print("需要数字")
while True:
try:
b = float(input('请输入b: '))
nb = float(b)
break
except:
print("需要数字")
while True:
try:
c = float(input('请输入c: '))
nc = float(c)
break
except:
print("需要数字")
if a == 0:
return ("a不可以为0")
if b**2 - a*c*4 < 0:
return ("根号内不能为负数")
q1 = ((-b + math.sqrt(b**2 - a*c*4)) / (a*2) )
q2 = ((-b - math.sqrt(b**2 - a*c*4)) / (a*2) )
return q1, q2
print(quadratic())