Set Operations with Venn Diagrams
Run the Set Operations with Venn Diagrams MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
This MicroSim connects visual Venn diagram regions to Python set operations. Students can:
- Edit Set A and Set B values
- Select an operation (Union, Intersection, Difference (A-B), Symmetric Difference)
- See the matching region highlighted
- Read the exact Python-style result expression
How to Use
- Start with the default sets:
A = {'apple', 'banana', 'cherry', 'date'}B = {'cherry', 'date', 'elderberry', 'fig'} - Click an operation button to highlight the corresponding Venn region.
- Observe bold items in highlighted regions and dimmed items outside the result.
- Add or remove values using the Set A / Set B input controls.
- Click
Swap A and Band compare howA - Bchanges. - Use the code panel to verify the Python operator and computed result.
Iframe Embed Code
1 2 3 4 | |
Lesson Plan
Grade Level
9-12 (High School Computer Science / Discrete Math)
Duration
10-15 minutes
Prerequisites
- Basic understanding of sets and membership
- Familiarity with Python literals and operators
- Difference between ordered sequences and mathematical sets
Activities
- Predict (3 min): Students predict which region each operation should select.
- Demonstrate (6 min): Students run all four operations and compare visual highlights with code output.
- Compute (4 min): Students modify set contents and recompute results.
- Reflect (2 min): Students explain why swapping sets changes
A - B.
Assessment
- Student correctly computes all four operations from the displayed sets.
- Student can explain visual region mapping to
|,&,-, and^. - Student can justify the effect of swapping A and B on difference.
References
- Python set types and operations: https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset
- Python tutorial - sets: https://docs.python.org/3/tutorial/datastructures.html#sets
- Set theory basics (union/intersection/difference): https://en.wikipedia.org/wiki/Set_(mathematics)