【问题标题】:x=x+1 syntax error inside a for loop in pythonpython中for循环内的x = x + 1语法错误
【发布时间】:2018-11-30 15:13:33
【问题描述】:

如果满足条件,我正在尝试在 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

【问题讨论】:

  • 统计错误所在行前的方括号个数
  • return 在函数之外,缺少右括号,quiz_dict 未定义,q_nos 未定义,ans_list 未定义....

标签: python for-loop increment


【解决方案1】:

Follwong 应该是函数

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多