13: Writing data to a file in python

Extend it:

Use and store data in files
Writing data to a file in python

For this challenge you will need write a children’s story to the file story.txt

Your story could be randomly generated or you could just write it line by line.

The starting point for your code just opens the file ready to write


  1. Start the story with “Once upon a time”

    Hint: Make sure you include a capital letter

  2. Make your story at least 10 lines long

    Hint: Don’t forget to add \n each time you want a new line

  3. Ask the user a question (e.g. their name) and use their answer in the story

    Hint: use input to ask a question and save the user’s answer into a variable

Leave a Reply

Your email address will not be published. Required fields are marked *