Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python函数中存在轻微的语法问题,尽管格式看起来不错(python,第7行)_Python - Fatal编程技术网

python函数中存在轻微的语法问题,尽管格式看起来不错(python,第7行)

python函数中存在轻微的语法问题,尽管格式看起来不错(python,第7行),python,Python,缺少一个右括号,第二组括号应为方括号: def product_of_positives(seq): positives=[] p=1 for a in range (len(seq)): if seq[a] > 0: positives.append(seq(a) for i in range (len(positive

缺少一个右括号,第二组括号应为方括号:

def product_of_positives(seq):
    positives=[]       
    p=1        
    for a in range (len(seq)):            
        if seq[a] > 0:                
            positives.append(seq(a)      
    for i in range (len(positives)):          
        p=p*positives[i]        
        print(p)  

seq=[1,2,3,4,5]
product_of_positives(seq)
应该是:

positives.append(seq(a)
以下是编辑后的代码:

positives.append(seq[a])

这将引发一个错误,因为
.append()
在其参数中不需要
for

请使用编辑器中的意图格式化代码。忽略格式化,您有一个未关闭的
此处:
正片。append(seq(a)
是的,这是因为您使用的是圆括号而不是方括号。请检查我的编辑@thedancingman 4321
def product_of_positives(seq):
    positives=[]       
    p=1        
    for a in range (len(seq)):            
        if seq[a] > 0:                
            positives.append(seq[a])      
    for i in range (len(positives)):          
        p=p*positives[i]        
        print(p)  

seq=[1,2,3,4,5]
product_of_positives(seq)