Issue with Quiz ^

I Think answer will be error because x is not define in whole function. and the priority of x =100 is local. so if we trying to execute this program then it will give Name error ???

image

@sriv.ansh

No , it will not give any error.

Beacuse it is printing only the value of x i.e., 100 which is locally defined in the function.
We are not printing the x which is outside the function.

Outside the function we are calling the function only.
X+=1 will not be an issue as it considered as just a statement, which is doing nothing in the program.

But if we run that program then it will give an error (Name Error) because x isn’t define. so because python is interpreted so when it will read x+=1 then it will Name error and because of that our f1() function will be not execute :slight_smile:

1 Like

@sriv.ansh

Have you tried running the code.

@dsedyoda Yesss mam …

@sriv.ansh
Ok, Let me talk with support than .

Will inform you after getting the answer from them.

@sriv.ansh

No it will not give you error as both x are different one is local variable having (x= 100)
And other is global variable having (x=+1).
Garbage collection will take of this other x (x=+1)
And function will give output as per local variable inside it.
So answer will be 100.

Do let me know if you understand this.

@dsedyoda How I can assure that the value of x in garbage collector is 100
have teams any where mentions that things

@sriv.ansh check the code it’s x= +1 (assigning) not x+=1(incrementing) , So our doubt was wrong in first place.

1 Like

Ohh… .it x=+1 ohhk I got it Thanks

1 Like