Journey log

Journey log

Recording a narrative.

Try


Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

Knowledge Organiser

x = [[]]

Declares x as an empty 2D list.


x.append([])

Adds a new row to 2D list x. The new row contains an empty list.


x[y].append(z)

Adds a new element z to row y in the 2D list x.

Investigate


Questions to think about with this program to check your understanding:

Purpose question

What is the purpose of the squared brackets inside the squared brackets in line 25?

book = [[]]

REVEAL ANSWER

To define an empty list inside an empty list.

This creates a table of unknown rows and unknown columns. It is easier to visualise like this...

Outside brackets
Inside brackets

Chapter 1

Story log 1


Story log 2

Chapter 2

Story log 3


Story log 4


Story log 5

...where the number of chapters and story logs can increase and decrease at any time. You can also visualise it like this:

[[Story log 1, Story log 2], [Story log 3, Story log 4, Story log 5]]

Reason question

Why has the programmer chosen not to define the number of indexes in line 25? I.e. why use a list instead of an array for storing data?

REVEAL ANSWER

Lists are dynamic. That means the number of indexes in the structure can grow and shrink as the program is running. With an array the number of indexes are static (fixed) when the program is written and cannot change. Using a list allows any number of chapters and story entries to be added to the book later. This is better for a situation where you may want to expand the story.

Make


Success Criteria

Change the program so that it:

  1. Outputs a heading at the beginning of each chapter.
  2. Outputs the story so far to a file called, `log.txt`, so that modding tools could read the data generated by the program and make use of it.

Typical inputs and outputs from the program would be:

CHAPTER 1

----------


Log 1 : I find myself alone on a strange world, unequipped and in danger. I have no memory of how I got here, no sense of a before.

Log 2 : My Exosuit at least seems to know what it's doing, and I am not dead yet...


CHAPTER 2

----------


Log 3 : I received a set of mysterious coordinates from an unknown source.

Log 4 : I followed the signal, and found the wreckage of an abandoned starship.

Log 5 : There was little to be gained from the wreck, but the distress beacon contained the hailing frequency labelled 'ARTEMIS'.

Help

Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.

Evaluate


Run your code to check that your program has met the success criteria and produces the required output.

CHAPTER 1

----------


Log 1 : I find myself alone on a strange world, unequipped and in danger. I have no memory of how I got here, no sense of a before.

Log 2 : My Exosuit at least seems to know what it's doing, and I am not dead yet...


CHAPTER 2

----------


Log 3 : I received a set of mysterious coordinates from an unknown source.

Log 4 : I followed the signal, and found the wreckage of an abandoned starship.

Log 5 : There was little to be gained from the wreck, but the distress beacon contained the hailing frequency labelled 'ARTEMIS'.