Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions