whenever I run following code of adding two lists in python below mentioned error appears
def add_lists(L1, L2):
R = []
for i in range(0, len(L1)):
R.append(L1[i]+L2[i])
return R
L2 = [3, 3, 3, 3]
L1 = [1, 2, 3, 4]
add_lists(L1, L2)
print("Resultant list of: ", str(L1), '& ' + str(L2), 'is', R)
this code yields NameError: name 'R' is not defined
Ris defined within your function, but not outside it: that's why you see this error. You should call your function and assign the result to a variable. Sayres = add_lists(L1, L2). Then you can useresin yourprintstatement.