Week 1 Exercise: Choose Your Own Adventure

Chris Tralie, heavily inspired by Bill Mongan

Overview / Logistics

The purpose of this exercise is to give you practice with python dictionaries, which will be very important during the second unit of our class, and which are important in many python data wrangling tasks in general. The idea for this exercise was inspired by an assignment by Bill Mongan.

Learning Objectives

  • Practice declaring variables, strings, and lists in python
  • Use proper data structures as keys and values in python dictionaries
  • Properly index python arrays
  • Choose an appropriate loop structure for a given task

Background

Choose Your Own Adventure books are a series of books from the '80s and '90s in which the reader takes a more active than usual role. In particular, the books are written in the second person, and they turn over key decisions to the reader. Based on these decisions, the reader jumps to different pages to see the outcome of those decisions.

In this exercise, you'll be designing a Choose Your Own Adventure-style program to tell a dynamic story. There are four pieces of information that you should represent in your program

  1. A list of places you can be in your world
  2. A little blurb describing each place
  3. A list of places you can travel to next from each place
  4. Which place you start, and which place ends

Your Below is a very simple example to illustrate this idea, which pretty much sums up my life as an instructor during quarantine last year (thank goodness those days are over for now...). The game starts in the office, and it ends whenever someone reaches the outside.

A sample run through the program might look like this

  • You are in the Office. The place where you frantically try to get everything ready for class. Where would you like to go?

    Options: [Kitchen, Bathroom]

    Input: Kitchen

  • You are in the Kitchen. The place where you heat up frozen food and sometimes (but rarely) cook. Where would you like to go?

    Options: [Office, Upstairs Bedroom, Outside]

    Input: Upstairs Bedroom

  • You are in the Upstairs Bedroom. The place you go rarely when you've finished your work for the day. Where would you like to go?

    Options: [Kitchen, Upstairs Bathroom]

    Input: Kitchen

  • You are in the Kitchen. The place where you heat up frozen food and sometimes (but rarely) cook. Where would you like to go?

    Options: [Office, Upstairs Bedroom, Outside]

    Input: Upstairs Bedroom

  • ......

Programming Task

You should create a dictionary called places whose keys are strings with the names of the different places you can go in your story. The values associated to different keys should be lists of strings. The first element in this array should be a description of the place, and the remaining elements in this array should be the strings of the places you can reach from this place. Your program should go through a loop where in each iteration, it prints the place you are and its description, followed by a list of places you can go. Then, you should wait for input from the user to say which place to go. Finally, you should have a constant string which represents where the loop starts, and a constant string to represent when the loop should terminate.

The example I gave is pretty boring (because it mirrors my life!). But you should feel free to be as creative as you want. It is recommended that you sketch your world out of paper before you translate it into code. We will share some of your examples on the class web site. Have fun!


Below is a solution to this problem:


Student Adventures

Below are the fabulous stories that students in our class came up with in very little time. Click through them to explore!

Choose Adventure
Location Description Next Step