locationpaster.blogg.se

Mad libs python code list random
Mad libs python code list random





%1 will be replaced by the first word in the input list, an object. These tell me where I am going to replace the words in the story. Then we have the story which contains markers like %1 A %1 flew across the road This could be any symbol that is unlikely to be in the story.

mad libs python code list random

Then there is a # symbol which divides up the objects part from the story part. The first part before the # symbol is the list of items I need to ask the user to input – I’ll call this the input list. Now let’s inspect the format of the madlibs. You can add as many stories as you like to the file as long as they are each on a separate line. Place,person# One day in %1 I saw %2 with a cat on their head. Inside my text file I made up some stories, each one on a different line, for example: object,person# A %1 flew across the road and knocked over %2. I wanted to provide a revision task for reading and writing to files as well as string manipulation, so I did it this way.įirstly, I started with a text file – let’s call it madlibs.txt. Obviously, the more entertaining the original story, the better the laughs will be at the end! How do I program it? Set up the text fileĪs with all programs, there are many ways of solving this. Lady Gaga went to London and bought a pencilcase We might end up with something like this:

mad libs python code list random mad libs python code list random

We then prompt the user to enter these words, in this case a name, a place and an object. We start with a story, containing several blanked out words. It’s a little bit like the game of consequences, but not quite the same. It’s based around the game of ‘Madlibs’ which we don’t really have in the UK, but Wikipedia says it is “a phrasal template word game where one player prompts another for a list of words to substitute for blanks in a story, usually with funny results”. Long time no blog! Things have been incredibly busy, especially as I’m also working on the #include hack day for 11-13 year old girls which will be held in June 2013!Īnyhow, I thought I’d put up a little game I created as a revision task for my upper 6th who have their January modules (*sniff*) coming up.







Mad libs python code list random