View the step-by-step solution to:

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

This program is about sets. Design 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}

Top Answer

Sample output: set1: {2, 3, 5, 6, 10} set2: {1, 6, 7, 9, 10} Union of set1 and... View the full answer

python.JPG

Sign up to view the full answer

Other Answers

Find the below logic for the program. Let me know if you have any doubt. For set1: import random #for random numbers set 1=... View the full answer

Output.PNG

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online