python中的for循环内x = x + 1语法错误

时间:2018-11-30 15:13:33

标签: python for-loop increment

如果条件满足,我试图在for循环中增加一个变量(计数)。但是,在递增语句中出现语法错误。请帮忙。

def count_ans():
    count=0
    for m in range(0,4):
        if quiz_dict[q_nos[m]==ans_list[m]:
            count += 1    #<--syntax error
return count

1 个答案:

答案 0 :(得分:0)

Folllwong应该是函数

def count_ans():

count=0
for m in range(0,4):
    if quiz_dict[q_nos[m]]==ans_list[m]:  ##### Square bracket was missing
        count += 1   
return count                        #### Return was outside the function