gpt4 book ai didi

python - 类型错误 : 'float' object is not callable error with bhaskara program

转载 作者:太空宇宙 更新时间:2023-11-04 07:08:26 26 4
gpt4 key购买 nike

#entrada de dados
a = int(input("valor de a "))
b = int(input("valor de b "))
c = int(input("valor de c "))
#
import math
#
d =b*b - 4 * a * c
#
if d < 0:
print('nao tem raizes reais')
elif d ==0:
raiz = (-1*b + math.sqrt(d))/(2 * a)
print('o valor e '), print(raiz)
elif d > 0:
raiz = (-1*b + math.sqrt(d))(2 * a)
raiz1 = (-1*b - math.sqrt(d))(2 * a)
print('as raizes sao'), print(raiz), print(raiz1)
#fim

我试着输入这段代码,但我得到了这个错误:

Traceback (most recent call last): File "C:/Python34/test podre.py", line 16, in raiz = (-1*b + math.sqrt(d))(2 * a) TypeError: 'float' object is not callable

怎么了?

最佳答案

python中不能用纯括号将两个对象相乘,需要用*分隔。

raiz = (-1*b + math.sqrt(d))(2 * a)

成为

raiz = (-1*b + math.sqrt(d))*(2 * a)

这是您编辑的代码:

a = int(input("valor de a "))
b = int(input("valor de b "))
c = int(input("valor de c "))
#
import math
#
d =b*b - 4 * a * c
#
if d < 0:
print('nao tem raizes reais')
elif d ==0:
raiz = (-1*b + math.sqrt(d))/(2 * a)
print('o valor e '), print(raiz)
elif d > 0:
raiz = (-1*b + math.sqrt(d))*(2 * a)
raiz1 = (-1*b - math.sqrt(d))*(2 * a)
print('as raizes sao'), print(raiz), print(raiz1)

关于python - 类型错误 : 'float' object is not callable error with bhaskara program,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28133148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com