Python无效语法为什么?

2024-09-26 18:02:52 发布

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

为什么这是无效的语法?你知道吗

if 0.9*x < d[o] < 1.1*x:

这是全部代码

def phipsd(d,p):
   a=[]
   lend = len(d)
   ad=np.array(d)
   for i in range(0,9):
       for o in range(0, len(d)):
           x = (500/(2**(i))*10**-6                 
           if 0.9*x < d[o] < 1.1*x:
               c = c + p[o]
       a.append([])
       b=a[i]
              b.append(c)

Tags: 代码inforlenifdefnp语法
2条回答

你引用的那句话不是你错误的根源。这条线是:

x = (500/(2**(i))*10**-6                 

请注意不匹配的括号。你知道吗

def phipsd(d,p):
   a=[]
   lend = len(d)
   ad=np.array(d)
   for i in range(0,9):
       for o in range(0, len(d)):
           x = (500/(2**(i))*10**-6    # Here is a SyntaxError, Because You've started 3 parentheses but terminated only 2. So, add a closing parenthesis in the right place.             
           if 0.9*x < d[o] < 1.1*x:
               c = c + p[o]
       a.append([])
       b=a[i]
       b.append(c)

查看评论

相关问题 更多 >

    热门问题