Extend it:

Use and store data in files
Reading data from a file in python

For this challenge you will read parts of a story from a file and use them to generate a random story.

The starting point for your code reads data from a file called words.csv and starts off your random story:

Challenges:

 
  1. Make a variable called food and set it to a random thing to eat that you’ve read from the file

    Hint: Use random.choice to choose a value from the list called foods which contains all the different foods read from line 4 of words.csv

  2. Add a new line to the file with things that might happen suddenly (e.g. met a dinosaur, fell in a hole, needed the loo)

    Hint: Remember that a csv file is just a text file with all values separated by commas , and new lines

  3. Make a variable called suddenly and use random.choice to choose what suddenly happens next

    Hint: You’ll also need to use readline and split to get the data from the CSV file

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.