Why this code says x not defined in line 5 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why this code says x not defined in line 5

def add_numbers(x, y): total = x + y return total print("This won't be printed") print(x*y) k=5;l=8 print(add_numbers(k, l))

15th Apr 2020, 7:32 AM
Jaweed
Jaweed - avatar
3 Answers
+ 5
Because it's outside the function and you can't access local variable outside the function.
15th Apr 2020, 7:37 AM
A͢J
A͢J - avatar
+ 2
i think, anything after return won't be printed
16th Apr 2020, 12:42 PM
akrep
akrep - avatar
+ 1
Because x & y is local variable , they only accessable in the function body.
16th Apr 2020, 1:19 PM
Zebi Zebi
Zebi Zebi - avatar