[英]Trying to do a basic code but generate an error
只是嘗試一些代碼:
a_leg = 5
b_leg = 5
hyp = (a_leg**2)(b_leg**2)
print(hyp)
我收到以下錯誤:
hyp = (a_leg**2)(b_leg**2)
類型錯誤:'int' object 不可調用
這是什么意思? 我知道這是非常基本的,但會感謝您的幫助。
謝謝
你得到這個是因為
hyp = (a_leg**2)(b_leg**2)
在編程語言中,您必須明確使用運算符。 在這種情況下,正確的代碼是:
hyp = (a_leg**2)*(b_leg**2)
注意這兩個括號之間的*
。
您收到此錯誤是因為:
(a_leg**2)
返回一個不可調用的 integer。 您可以制作 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.