Oct 23: Sets, Input Validation
Meet in EnGeo 2208
Learning Objectives
After today's class, you should be able to:
- Create a set, and test membership using the
inoperator. - Use a set to remove duplicates or track what you have seen.
- Write a loop that repeats until the user enters a valid value.
Lesson Outline
Presentation [10 min]
- Python sets: adding/removing items, set methods
Activity [20 min]
va_schools = {"JMU", "GMU", "VCU", "VT", "ODU", "WM", "UVA"}
two_letter = {"MU", "VT", "ND", "WM", "BC"}
type(va_schools)
len(two_letter)
"ND" in va_schools
"JMU" not in two_letter
len(va_schools.union(two_letter))
va_schools.intersection(two_letter)
two_letter.difference(va_schools)
Example [20 min]
- Simple word game using sets: hangman.py