python中的未知语法错误(我真的找不出我的错误在哪里)

2024-04-20 00:47:14 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:

import math

k = int(input("Give the term number: "))
result = 0

for x in range(k):
    result += 2*pow(-1,k)*pow(3,(0.5-k))/(2k+1)

print ("After ", k, "terms, ", "the appoximation is ", result)

语法错误出现在第7行,这是for循环之后的结果。 我知道这类错误通常是缺少括号等,但我真的不知道我的错误在哪里。你知道吗


Tags: theinimport密码numberforinput错误
2条回答
import math
k = int(input("Give the term number: "))
result = 0

for x in range(k):
    result += 2*pow(-1,k)*pow(3,(0.5-k))/((2*k)+1)
print ("After ", k, "terms, ", "the appoximation is ", result)

下一行出错

result += 2*pow(-1,k)*pow(3,(0.5-k))/`(2k+1)`

2k+1应该是2*k

相关问题 更多 >