首页 > 解决方案 > “UnboundLocalError:分配前引用的局部变量'输入'”几乎适用于我的代码中的每个输入

问题描述

x = int(0)
ans1 = int(0)
ans = int(0)  
with open('risk_q.txt') as r:
    for x in range(12): 
        mylist = [line.rstrip('\n') for line in r] 
        ans1 = int(input())             #Error occurs in this line

此错误发生在代码前面的不同输入中,因此我在函数之前获取输入,然后通过函数的参数将其传递。

标签: pythonpython-3.x

解决方案


检查您的代码。看起来好像您已用作input变量名,因此覆盖了内置函数。


推荐阅读