[英]Trying to do a basic code but generate an error
Just trying some code out:只是尝试一些代码:
a_leg = 5
b_leg = 5
hyp = (a_leg**2)(b_leg**2)
print(hyp)
I get the below error:我收到以下错误:
hyp = (a_leg**2)(b_leg**2)
TypeError: 'int' object is not callable类型错误:'int' object 不可调用
What does this mean?这是什么意思? I know it is very basic but will appreciate your help.
我知道这是非常基本的,但会感谢您的帮助。
Thanks谢谢
You are getting this because of你得到这个是因为
hyp = (a_leg**2)(b_leg**2)
In programming languages you have to explicitly use operators.在编程语言中,您必须明确使用运算符。 In this case, the correct code would be:
在这种情况下,正确的代码是:
hyp = (a_leg**2)*(b_leg**2)
notice the *
between those two brackets.注意这两个括号之间的
*
。
You are getting this error because:您收到此错误是因为:
(a_leg**2)
returns an integer that is not callable.返回一个不可调用的 integer。 You can make a function to calculate the hypotenuse like these:
您可以制作 function 来计算斜边,如下所示:
from math import sqrt
a_leg = 5
b_leg = 5
def hyp(a, b):
h = sqrt((a**2) + (b**2))
return h
print(hyp(a_leg, b_leg))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.