[This was originally posted last year, on an old blog to promote computational thinking and programming in schools. I’ll be reposting these over the next month as I think they’re still useful to schools embarking on the new Computer Science course]
Here’s a nice Python lesson. I’ve written some very basic code that recreates the classic game of Consequences – which you may, or may not have heard of! It’s a simple premise – the first player writes down an adjective, folds over their paper, then the second player writes down a name, folds the paper over, and so on. Once both / all players have inputted their allocated text types (adjectives, names, places, speech etc), the paper is unraveled and a hilarious (yes, HILARIOUS) if somewhat random story unfolds.
This link explains and demonstrates the game a little better than me.
The code for this game is ridiculously simple. Essentially you have eleven different input prompts, then print them all out at the end, with a few sentence links added in.
The only bit that took a while to work out is reenacting the secrecy element (ie the paper folding in the original game). You’d think that Python would have some nice easy code to disable the ‘echo’ it displays (in other words, stop Python from printing each part of your story before you’ve told it to print).
Well, unlucky. Python has no clear way of not echoing. Neither is there a simple way of text-masking (like when you type your password in and it appears as ******). There are work-arounds and module-imports that can do those things or similar, but they make the code overly complicated and would ruin a lesson for children.
The closest I’ve found is a fairly cheap but workable
print (“\n” * 100)
It feels cheap, because all it does is print 100 blank lines, therefore ‘pushing’ each part of the story off the screen. However it’s easy code, easy to explain to students, and crucially, allows them to play the game as pairs / groups. Obviously students would have to divert their eyes whilst their partner types in their own part of the story, as it doesn’t disappear until they’ve finished entering it.
The best part of it all is that the results can be really funny, and students get to learn about printing multiple strings and variables within one single print function.
def main(): adj1 = input(“Enter the first adjective “) print (“\n” * 100) adj2 = input(“Enter the second adjective “) print (“\n” * 100) manname = input(“What was his name? “) print (“\n” * 100) adj3 = input(“Enter the third adjective “) print (“\n” * 100) womanname = input(“What was her name? “) print (“\n” * 100) loc1 = input(“Where did they meet? “) print (“\n” * 100) gift1 = input(“What gift was given? “) print (“\n” * 100) said1 = input(“What did he say to her? “) print (“\n” * 100) said2 = input(“What did she say to him? “) print (“\n” * 100) cons = input(“What was the consequence? “) print (“\n” * 100) wtw = input(“What did the world say about it? “) print (“\n” * 100) print(“The “, adj1, ” and “, adj2, ” “, manname, ” met the “, adj3, ” “, womanname, ” in “, loc1, “; he gave her “, gift1, ” and said to her “, said1, ” She said to him: “, said2, “; and the consequence was “, cons, “, and the world said ‘”, wtw, “.'”)