Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

Coding Quiz - Find Union and Intersection

In this coding quiz, you'll write a function to find the union and intersection of two sets.

The task is to write a function that receives two sets, set1 and set2, from the user, computes their union and intersection, and returns them as a tuple.

The first element of the returned tuple should be the union, and the second element should be the intersection.


Write Code
def solution(set1, set2):
# Write your code here
return



Constraints

  • The input sets will contain integers.

  • Sets will be represented using Python's set data type.




Example Input/Output

  • Input: set1 = {1, 2, 3}, set2 = {2, 3, 4}

  • Output: ({1, 2, 3, 4}, {2, 3})


  • Input: set1 = {5, 6, 7}, set2 = {7, 8, 9}

  • Output: ({5, 6, 7, 8, 9}, {7})

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.