Why can you double a train fare in Python, but not double a call that prints a ticket?
Your group is building a ticket machine for a school trip to Galway. One call works out the fare. Another prints a ticket on screen. If you need two tickets, can you multiply the second call by two?
Use the trace skills you already have. The call passes four into the fare function. The function adds two to four and returns six. That six goes into price, ready for the next line to use. Nothing has been printed.
You pass six to show ticket. The print instruction runs, and a six-euro ticket appears on screen. That visible change is a side effect of the call. You can call this function a procedure because its main purpose is to perform an action.
You call show ticket with six. Think about the difference between giving a function a value, getting a value back, and having the function do something. Pick the event that is a side effect of this call.
Read the body of show ticket. It has one instruction, print. When the call runs with six, you see the ticket. Then the function reaches the end without a return statement. Python returns None automatically, so result holds None, even though the screen shows the ticket.
This time, call show ticket with eight and assign the result. As the call runs, the ticket appears first. When the function finishes, result gets None. Then print result runs, so you see None on a second line.
Now result gets the value of calling show ticket with nine. The next line prints result. What appears first, and what appears on the next line? Pick the option with both lines in order.
On the left, Python runs show ticket once, so one ticket appears. Then it tries to multiply None by two and raises a type error. On the right, each call performs the display action once. Two calls give you two tickets.
Outline the plan in pseudocode before you write Python. First, call fare with four and store the price. Then repeat the display step twice. Each time, pass the same stored price to show ticket so that both tickets show the same fare.