Question: PROBLEM 2 This program will demonstrate your ability to work with sets. Create a file named Lab 0 9 P 2 . py . Write

PROBLEM 2
This program will demonstrate your ability to work with sets.
Create a file named Lab09P2.py. Write a program that does the following:
a) Generate 8 random integers between 1 and 16 inclusive using the randint function from the random module. Store the random integers in a set named set1. Display the set. Please note that the set may have less than 8 elements because some of the random integers generated may be duplicates.
b) Create another set named set2 in the same way set1 was created.
c) Find and display the union of set1 and set2. Make sure to include something in your output that indicates your output is for this step (see sample output).
d) Find and display the intersection of set1 and set2. Make sure to include something in your output that indicates your output is for this step (see sample output).
e) Find and display the difference of set1 and set2. Make sure to include something in your output that indicates your output is for this step (see sample output).
f) Find and display the symmetric difference of set1 and set2. Make sure to include something in your output that indicates your output is for this step (see sample output).
g) Use set comprehension to select the numbers less than 10 from the union set in Step c and store them in a set. Display this set. Make sure to include something in your output that indicates your output is for this step (see sample output).
Sample output:
set1: {1,7,10,13,16}
set2: {4,5,7,8,9,13,14}
Union of set1 and set2: {1,4,5,7,8,9,10,13,14,16}
Intersection of set1 and set2: {13,7}
Difference of set1 and set2: {16,1,10}
Symmetric difference of set1 and set2: {1,4,5,8,9,10,14,16}
Less than 10 in union of set1 and set2: {1,4,5,7,8,9}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!