Can a ticket machine use the same name to show €2 now and €3 a moment later?
A ticket machine shows a fare of two euro. Then it adds one euro and shows three. Both display instructions can use the same name, fare. What changes between the two displays?
This Python line displays a greeting. The quotes tell Python which characters belong to the text. The comment underneath shows what you see on screen: Fáilte, without the quotes.
The first line assigns the text Fáilte to the name greeting. A value made of text is called a string. The name greeting is a variable. On the next line, you leave off the quotes so Python looks up the value of greeting and prints Fáilte.
The first instruction assigns the text Cork to the name station. The next instruction passes station to print without quotes around the name. What appears on screen? Pick the output.
First, fare is set to two. On the next line, read the right side first. Fare still means two while Python works out two plus one. Once it has three, Python assigns that result to fare. The value before the update was two. Afterwards, it's three.
This time, fare starts at five. The next instruction sets fare to fare plus one, and the final instruction prints fare. Which value does the print instruction display? Pick an answer.
If you treat fare equals fare plus one as an equation, both sides would use the same unknown. There's no solution: a number can't equal itself plus one. To trace the Python assignment, use the current value on the right, then assign the result to fare.
An exam question might say, ‘State the output of the following code.’ Set fare to seven, then read the right side of the update first: seven plus one gives eight. Assign eight to fare. The final line prints eight because that's the value fare refers to now.