Cards Against Humanities
Cards Against Humanities tutorial
- Understand and use sequence in an algorithm
- Understand and use iteration in an algorithm (FOR and WHILE loops)
- Understand and use selection in an algorithm (IF, Else and Else if)
- Understand and use data structures in an algorithm (for example, Lists, Tables or Arrays)
EDUCATOR: COMPUTATIONAL THINKING COMPETENCIES:
COMPUTER SCIENCE EDUCATORS:
CSTA K–12 CS Standards:
AREA OF LEARNING AND EXPERIENCE: Science and Technology:
Computation is the foundation for our digital world.
Progression step 3
- I can use conditional statements to add control and decision-making to algorithms.
- I can identify repeating patterns and use loops to make my algorithms more concise.
- I can explain and debug algorithms.
Progression step 4
- I can decompose given problems and select appropriate constructs to express solutions in a variety of environments.
- I can select and use data structures that efficiently manage data in algorithms.
- I can plan and implement test strategies to identify errors in programs.
Progression step 5
- I can identify, define and decompose problems, choose appropriate constructs and express solutions in a variety of environments.
- I can use file-handling techniques to manipulate data in algorithms.
- I can test, evaluate and improve a solution in software.
Cards Against Humanities is a phrasal template word game, where one player prompts other players for a list of words to substitute blanks in a question or phrase before reading out the completed phrase or question aloud.
We start with a question or phrase containing one or more blanked out words. Here’s a basic example:
Rumble in the _______.
We then prompt the user to fill in the gaps, in this case, with a noun or place. We might end up with something like this:
Rumble in the Toilet.
In this lesson, students will learn how to code a “Cards Against Humanities” game in Python. The game will work by prompting the user to enter some words (e.g. person’s name, noun, adjective, place, object etc.) and substitute these with blanks in a quote from History, phrase in French or Spanish, or Geography question etc.
There are several ways to create a Cards Against Humanities game in Python. In our version, the program will pick a phrase or question at random from a list of humanities subjects (History, Geography, Modern Foreign Languages or Religious Studies). However, before the students start coding their “Ultimate Cards Against Humanities” game, start them off with a simplified with a simple version:
Step 1. Creating your first Cards Against Humanities game
Start by sharing the following code snippet. Challenge the students to predict what will happen before revealing the answer.
noun = input("Enter a noun: ")
print("Rumble in the " + noun)
- Have the students copy the code then modify it so that the game requires 2 or more user inputs (i.e. a phrase or questions that contains 2 or more blanks).
verb = input("Enter a verb: ")
verb2 = input("Enter another verb: ")
plural = input("Enter a plural noun e.g. Cats or Dogs: ")
print("That's one small " + verb + " for man, one giant " + verb2 + " for " + plural.")
In the next version, the students will create a text file containing several questions or phrases (containing blanks). Just like the previous example, the program will ask the user to enter one or several nouns, verbs, adjectives etc. but this time will pick a question or phrase at random from a text file.
Step 1. Introducing the ‘String replace method’
Before creating their text file, have the students first explore the ‘string replace method’.
Explain to the students that sometimes, in Python, you find yourself in a situation where you want to modify the contents of string by replacing one piece of text with another. Luckily, Python makes this job easy thanks to the string replace method.
1. To help them understand how the .replace() method works, share the following code with the students.
Tip: As before, challenge the students to predict what the code will do before revealing the answer.
string = "This is a string"
string = string.replace("is", "was")
- Have the students copy the code then modify it by changing the string or changing the replacement text.
Explain that, in the above example, the line ‘string = string.replace(“is”, “was”) looks for the word “is” in the sentence and replaces it with the word “was”. Inform the students that they will be using the .replace() method to replace the blank(s) in their Cards Against Humanities game with the word(s) input by the user.
Step 2. Creating the text file
Next, the students need to create a text file for their Cards Against Humanities game, for the purpose of this example, we will call the file 'cards.txt'.
- Challenge the students to create a list of historical quotes, geography questions or phrases in French/Spanish etc. and store each one on a different line – They should type in the word ‘blank’ for the word they want to be replaced, for example:
MFL: Je voudrais un ananas is French for I would like a blank
History: In the final battle at Hastings, King Harold was killed by a blank in the eye
Geography: Plucking is a process of erosion that occurs during blank
1. Share the following worked example with the students:
# Program to read a random question or phrase from a file and print the game card with the user's response
# Open the Cards Against text file
f = open('cards.txt','r')
# Read the whole file and store each line in a list
cardText = f.readlines()
# Choose a random line from the list
card = random.choice(cardText)
# Ask the user to input a noun
noun = input("Enter a noun: ")
# Replace the blank with the user's input
card = card.replace("blank", noun)
# Print out the game card including the user's response
- Have the students copy the code then modify it so that it displays the randomly chosen card before prompting the user for their response.
Cards Against Humanities Solution
Taking it further
Python web, python programming language, python programming, python coding.