python - NameError: name 'result' is not defined -
I have written a very simple program in Python
for the category I (1 , 1000): if (i% 3 == 0) and (i% 5 == 0): result + = i other: print ('sum is {}'. Format (result))
When I try to compile the problem, I get an error.
Name error: Name 'Result' is not defined
This statement:
is the result of + i =
:
result = result + I
But, for the first time this statement has reached your loop, variable result
is not defined, so the right hand of that assignment statement is evaluated Does not happen.
Comments
Post a Comment