0
How to fix 'refrenced before assignment' in Python ?
I do know exactly know how can I fix this error ... but this is only a part of my code , please show me my mistake : check = True def Apply(string , i ,j): ... cmp_2 = res if cmp_1 == cmp_2: check = False if check == True: ... And in the last line , the error raises ...tell me to send my complete code , if you need it ...
9 ответов
+ 4
Just as Lisa pointed out, check is not declared if cmp_1 != cmp_2
The solution is to declare it before testing the condition
check = True
if (cmp_1 == cmp_2):
check = False
Alternatively you can write it in a single line like this
check = cmp_1 != cmp_2
+ 2
Ali_combination check only exists if cmp_1 == cmp_2 (line 55), so if this statement is not true, it cannot be referenced in the following
the Apple function cannot refer to the check var of line 46
+ 1
Is there a variable named cmp_1 because it is not declared in the code snippet you shared
+ 1
I think you have to share the complete function body
0
Ore yep..its already declared .
0
Ore here you are https://code.sololearn.com/ca12a2311a13/?ref=app
0
Ore sorry sir ... didn't you figure the bug out ? Im still stuck with it -_-
0
Lisa I really didnt get it ... what should I change ? The if statement should be included ... otherwise the progarm won't work ..