Extend it:
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:
- 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 calledfoods
which contains all the different foods read from line 4 ofwords.csv
- 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 - Make a variable called
suddenly
and userandom.choice
to choose what suddenly happens next
Hint: You’ll also need to use
readline
andsplit
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.