Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python... I need help with sets. B, C and f I dont quite know what to do. I kinda did something for C but Im

Python... I need help with sets. B, C and f I dont quite know what to do. I kinda did something for C but Im pretty sure its wrong since it only looks for duplicates and not doubles. This is suppose to be about sets.

def a(set1,set2,set3): #Create a new set of all elements that are in set1 or set2, but not both

set1new=set1.difference(set2)

set2new=set2.difference(set1)

new_set=set1new|set2new

print("A. Inside set 1 and 2 but not both:",new_set)

def b(set1,set2,set3): #Create a new set of all elements that are in only one of the three sets set1,set2, and set3.

pass

def c(set1,set2,set3): # Create a new set of all elements that are exactly two of the sets set1, set2, and set3.

set12=set1.intersection(set2)

set13=set1.intersection(set3)

set23=set2.intersection(set3)

new_set=set12|set13|set23

print("C. A list of elements that are repeated twice", new_set)

def d(set1,set2,set3): # Create a new set of all integer elements in the range 1 through 25 that are not in set1.

interger_set={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}

new_set=interger_set.difference(set1)

print("D. Numbers 1 to 25 that are not in Set 1:",new_set)

def e(set1,set2,set3): # Create a new set of all integer elements in the range 1 to 25 that are not in any of the three sets set1, set2, or set3.

interger_set={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}

new_set=interger_set.difference(set1)

new_set=new_set.difference(set2)

new_set=new_set.difference(set3)

print("E. Numbers 1 to 25 that are not in sets 1, 2 aor 3:",new_set)

def f(set1,set2,set3): # Create a new set of integer elements in the range 1 to 25 that are not in all three sets set1, set2, and set3.

pass

def main ():

set1 = {1,2,3,4,5}

set2 = {2,4,6,8}

set3 = {1,5,9,13,17}

a(set1,set2,set3)

b(set1,set2,set3)

c(set1,set2,set3)

d(set1,set2,set3)

e(set1,set2,set3)

f(set1,set2,set3)

if __name__=="__main__":

main()

image text in transcribed

6 def a(set1, set2,set3): #Create a new set of all elements that are in set1 or set2, but not both set1new set1.difference(set2) set2new-set2.difference(set1) new_set-setlnew| set2new print ("A. Inside set 1 and 2 but not both.", new-set) 12 13 def b(set1, set2,set3): #Create a new set of all elements that are in only one of the three sets set1, set2, and set3. pass 15 16 17 18 19 20 def c(set1, set2, set3): # Create a new set of all elements that are exactly two of the sets set1, set2, and set3. set12-set1.intersection (set2) set13-set1.intersection (set3) set23-set2.intersection(set3) new_set-set12 set13 set23 print("C. A list of elements that are repeated twice", new_set) 22 23 def d(set1,set2,set3): # Create a new set of all integer elements in the range 1 through 25 that are not in set1. interger_set 11,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) new_set-interger_set.difference(set1) print("D. Numbers 1 to 25 that are not in Set 1:", new_set) 25 26 27 28 29 30 31 32 def e(set1,set2,set3): # Create a new set of all integer elements in the range 1 to 25 that are not in any of the three sets set1, set2, or s interger_set (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) new_set-interger_set.difference(set1) new_set new_set.difference(set2) new_setanew_set.difference(set3) print("E. Numbers 1 to 25 that are not in sets 1, 2 aor 3:", new_set) 34 def f(set1, set2,set3): # Create a new set of integer elements in the range 1 to 25 that are not in all three sets set1, set2, and set3. 35 36 37 38 39 def main ): 40 41 42 43 as set1 11,2,3,4,5h set2 12,4,6,8 set3 {1,5,9,13,17) a(set1, set2,set3) b(set1, set2,set3) c(set1, set2,set3) d(set1, set2,set3) e(set1, set2,set3) f (set1,set2,set3) 45 46 48 49 50 if_name"main_" Screenshot 6 def a(set1, set2,set3): #Create a new set of all elements that are in set1 or set2, but not both set1new set1.difference(set2) set2new-set2.difference(set1) new_set-setlnew| set2new print ("A. Inside set 1 and 2 but not both.", new-set) 12 13 def b(set1, set2,set3): #Create a new set of all elements that are in only one of the three sets set1, set2, and set3. pass 15 16 17 18 19 20 def c(set1, set2, set3): # Create a new set of all elements that are exactly two of the sets set1, set2, and set3. set12-set1.intersection (set2) set13-set1.intersection (set3) set23-set2.intersection(set3) new_set-set12 set13 set23 print("C. A list of elements that are repeated twice", new_set) 22 23 def d(set1,set2,set3): # Create a new set of all integer elements in the range 1 through 25 that are not in set1. interger_set 11,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) new_set-interger_set.difference(set1) print("D. Numbers 1 to 25 that are not in Set 1:", new_set) 25 26 27 28 29 30 31 32 def e(set1,set2,set3): # Create a new set of all integer elements in the range 1 to 25 that are not in any of the three sets set1, set2, or s interger_set (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) new_set-interger_set.difference(set1) new_set new_set.difference(set2) new_setanew_set.difference(set3) print("E. Numbers 1 to 25 that are not in sets 1, 2 aor 3:", new_set) 34 def f(set1, set2,set3): # Create a new set of integer elements in the range 1 to 25 that are not in all three sets set1, set2, and set3. 35 36 37 38 39 def main ): 40 41 42 43 as set1 11,2,3,4,5h set2 12,4,6,8 set3 {1,5,9,13,17) a(set1, set2,set3) b(set1, set2,set3) c(set1, set2,set3) d(set1, set2,set3) e(set1, set2,set3) f (set1,set2,set3) 45 46 48 49 50 if_name"main_" Screenshot

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

Students also viewed these Databases questions

Question

E 1 =1

Answered: 1 week ago

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

3. You can gain power by making others feel important.

Answered: 1 week ago