Why this code is giving error in output ? | SoloLearn: Learn to code for FREE!


Why this code is giving error in output ?

8/10 548 SEC Remaining QUIT What is the output of the following program? i=0 def foo(i):    i=i+1    return i foo(1) print(i)

6/4/2020 3:04:17 PM

Md Sahil

3 Answers

New Answer


You are return a value so it requires a variable to store it so instead of foo(1) use this: i=foo(1) Then it will be correct. Happy coding


it is not an code error, it is a logical error, the value of i will never change because the varable "i" outside the functcion isn't the same variable "i" inside the function


ok, it's giving an IndentationError bcz there are 3 space indentations not 4. Use 4 spaces or 1 tab before i=i+1 and return i