And what happens is that I don’t understand what the code refers to “for x in D”. I understand that D refers to the dictionary, but what does “for x” refer to? What is x in that dictionary? I tried to change “for x” to “for z” and it gives me the following result:
cherry game
cherry game
So what do those variables refer to in that dictionary?
Also why the professor types print(x, D) instead of just print(x)?
x is just a variable name that represents the Dictionary keys that are iterated over. You could name the variable anything. Typically, you should name it what the variable represents. I would name the variable key because that is what it is.
You will need to post your actual code to show us how you produced the above output, because only changing the variable to z would not do this.
Like I said, there had to be some code above the other code you posted. In the first for in loop, the last value of x is “cherry” which is why you get:
cherry game
cherry game
printed. The second for in loop just prints x and D[x] twice.
The s = 0 is defining s and initializing its value to 0.
The i gets defined when it is written in the for in range.
They are just variables. I assume the s starts a zero so the line:
s = s + args[i]
can work. In the end, it just represents a sum, though the return statement is not indented correctly to achieve the sum of all the arguments passed to the function.
You should probably take a beginners course in Python before trying to learn Python for Data Science. Do some research on the range method and you learn what the first value of i is in a for i in range loop.