Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

This program is about sets. Write a Python program to do the following: (a) Generate 5 random integers between 1 and 10, inclusive. Store the

This program is about sets. Write a Python program to do the following:

(a) Generate 5 random integers between 1 and 10, inclusive. Store the random integers in a set named set1. Display the set. Please note that the set may have less than 5 elements because some of the random integers generated may be redundant.

(b) Generate 5 random integers between 1 and 10, inclusive. Store the random integers in another set named set2. Display the set. Please note that the set may have less than 5 elements because some of the random integers generated may be redundant.

(c) Find and display the union of set1 and set2.

(d) Use set comprehension to select odd numbers from the union and store them in a set. Display this set.

(e) Find and display the intersection of set1 and set2.

(f) Find and display the symmetric difference of set1 and set2.

The following is an example.

set1: {9, 10, 1, 7}

set2: {8, 1, 7}

Union of set1 and set2: {1, 7, 8, 9, 10}

Odd numbers in union of set1 and set2: {1, 9, 7}

Intersection of set1 and set2: {1, 7}

Symmetric difference of set1 and set2: {8, 9, 10}

Please write code in pycharm or something similar

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_2

Step: 3

blur-text-image_3

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 explore these related Databases questions