0
0
Pythonprogramming~15 mins

Union and intersection in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Union and Intersection of Sets
๐Ÿ“– Scenario: You are organizing a community event and have two lists of people who signed up for two different activities. You want to find out who signed up for either activity and who signed up for both.
๐ŸŽฏ Goal: Build a Python program that finds the union and intersection of two sets of names.
๐Ÿ“‹ What You'll Learn
Create two sets with exact names
Create a variable for union of the two sets
Create a variable for intersection of the two sets
Print the union and intersection sets
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Finding union and intersection is useful when combining or comparing groups of people, items, or data in real life, like event planning or inventory management.
๐Ÿ’ผ Career
Understanding set operations is important in data analysis, software development, and database management where you often need to combine or filter data.
Progress0 / 4 steps
1
Create two sets of names
Create a set called activity1 with these exact names: 'Alice', 'Bob', 'Charlie'. Also create a set called activity2 with these exact names: 'Bob', 'Diana', 'Edward'.
Python
Need a hint?

Use curly braces {} to create sets and separate names with commas.

2
Create union and intersection variables
Create a variable called union_set that stores the union of activity1 and activity2. Create another variable called intersection_set that stores the intersection of activity1 and activity2.
Python
Need a hint?

Use the .union() method for union and .intersection() method for intersection.

3
Print the union and intersection sets
Write two print statements: one to display union_set and one to display intersection_set.
Python
Need a hint?

Use print() to show the sets on the screen.

4
Run and check the output
Run the program and check that the output shows the union set with all unique names and the intersection set with names common to both activities.
Python
Need a hint?

The first printed set should have all five unique names. The second printed set should have only 'Bob'.