How this value 2 ,5and 9 comes?

How this value 2 ,5and 9 comes?

Can you provide the exercise url? Very likely these values where already in the list, must be somewhere earlier in the exercise information.

this is the exercise link:

Why it comes to print a huge list of student names if i do not assign line 4 to a variable.

It works only when i assign to some variable, why the previous code was not working?
And why this one works?

that has nothing to do with assignment

you’re changing two things and asking why one of them is causing a difference
it’s the other thing that caused the difference

But how it comes when i assign to a variable, the answer comes true?
You said that it has nothing to do with assignment.

because you changed something else as well

sir, can you also share your solution for this?
It will be very helpful for me.

if you have a variable that you want to remove, you can replace all uses of it with its definition

a = x
b = a + a

remove a:

b = x + x

after removing the assignment from your code, you can compare to find your other difference

like I’ve been saying, you have two differences. you’re looking at the wrong one. look at the other difference.

Hi are you satisfied with this solution?

I don’t know what you’re asking.

But you have these two:

stu = all_students.pop()

note that the second one completely ignores the return value of pop, while the other does something with it

is there any alternative solution without using assignment?

assignment has nothing to do with it, that’s not the difference

if you only use a variable once then just go ahead and replace its use with its definition

stu = all_students.pop()

see this, if i dont use variable, i get errors

You’re trying to pop it 12 times
nothing to do with variables

Could you please share me your way to solve in easy method?
As you have also said , nothing to do with variable.
So, I am really confused now .
Explain me please with your code.

Thanks in advance

Read your code.
You make 6 iterations.
Each iteration you call pop twice
6 * 2 = 12 calls to pop
there are 10 items in the list, the 11th time you call pop it’ll crash

The instructions say that you should do something 6 times. pop a value, put it in the other list.

is this correct now?

I thought you wanted to remove that variable. You just renamed it, no difference.


x = 3 + 4
y = x + 5

is the same as:

y = (3 + 4) + 5

the variable makes no difference

but you’re doing this instead:

y = 27 + 5

which doesn’t just remove the variable, but change the value as well. two differences, and the variable isn’t the cause. changing the value is the cause.

In the last line, how does it come 27 ?