Question

can someone please answer this Python code?

Problem 5 and write code that would find the union, intersection, and Read the documentation for sets difference of the sets

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

1 #Given sets A and B 2 A={George, Jim, John, Blake, Kevin, Michael} 3 B={George, Katie, Kevin, Michelle,

CODE (for copy):

#Given sets A and B
A={'George','Jim','John','Blake','Kevin','Michael'}
B={'George','Katie','Kevin','Michelle','Ryan'}
#Union of set A and B
print('A union B:'+str(B.union(A))+"\n")
#Intersection of set A and B
print('A intersection B:'+str(B.intersection(A))+"\n")
#Diffrenece of set A and B
print('A diffrence B:'+str(A-B))

OUTPUT:

A union B:set([Michelle, Blake, Jim, Michael, Ryan, John, George, Kevin, Katie]) A intersection B:set([Geo

Add a comment
Know the answer?
Add Answer to:
can someone please answer this Python code? Problem 5 and write code that would find the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The question exercises the union, intersection, and the intersection operations of two set of strings (names)....

    The question exercises the union, intersection, and the intersection operations of two set of strings (names). For this type of problem, you need to preserve the original sets from being modified by some of the set method. You can used the clone( ) method to copy the sets or simply create another set using the same array contents as the original. You can find an example of the clone() for the LinkedHashSet set in   the provided “skeleton” program (assign8_Q3.java) code...

  • Write the code in PYTHON and please provide the full code, thank you! Write a program...

    Write the code in PYTHON and please provide the full code, thank you! Write a program that plots two functions: f(x) = x2 and g(x) = ax. Write it in such a way that the intersection points are marked with an X, for arbitrary a. • You may use your favorite ready-made function to find the intersection points, if not: • One possible way to tackle this problem is to put both function values in arrays and check using a...

  • Can someone please rewrite this code using a while loop? Please write it in python. #The...

    Can someone please rewrite this code using a while loop? Please write it in python. #The winning number my_number = 12 #variable for the input name user_n = input("Hello! What is your name?") #Ask the user print("Well",user_n,": I am thinking of a number between 1 and 20." + "Take a guess.") user_n = float(input("Take a guess.")) #if statements if user_n == my_number: print("Good job" ,user_n, "You guessed my number!") if user_n > my_number: print("Your guess is high. You lose.") if...

  • Question 5 5. Write python code for the given for the problem: Ex: Working group has...

    Question 5 5. Write python code for the given for the problem: Ex: Working group has 8 members. Three will be assigned to lead the group (no difference in leadership positions). If there are 3 women and 5 men in the group, what is the probability of exactly 1 woman being assigned to the leadership (if assigned randomly)?

  • Could someone please help me solve this in Python? Brief explanation of the code comments would...

    Could someone please help me solve this in Python? Brief explanation of the code comments would be greatly appreciated. indices_second_biggest: This function returns a list containing the indices of the second largest value in its sole argument, a nonempty matrix (list of lists), i.e. [row index, col index]. If the largest value occurs more than once, it counts as the second largest also. If there is only one element in the matrix, return [0, 0].

  • This is for programming using Python with the JES software. Please write the code with the...

    This is for programming using Python with the JES software. Please write the code with the proper indentation. Thanks! Problem 1: Write a function that takes 2 arguments (integer or float) and computes the sum, difference, product, and quotient of the arguments. Once you calculate the values you should print out statements telling the user what arguments we used to compute the values and what the result of each calculation (your function should produce 5 lines of output in the...

  • Python Programming please Write a piece of code that gets a string variable (IP) from the...

    Python Programming please Write a piece of code that gets a string variable (IP) from the user (ex: “192.168.10.1”) and converts the decimal IP to binary mode. Output would be the octet in decimal format and next to it the octet in binary. Tip: Use the bin() built-in function. Example: Input: “192.168.10.1” Output: 192 – 11000000 10 – 10101000 10 – 00001010 1 – 00000001

  • can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp,...

    can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's...

  • Help writing MatLab code Lab Assignment 5-Employees Average Hours CSCI 251 Problem Statement Suppose the weekly...

    Help writing MatLab code Lab Assignment 5-Employees Average Hours CSCI 251 Problem Statement Suppose the weekly hours for all employees are stored in a text file where each line contains the employee name followed by the hours worked for each day of the week. The data is stored as follows (data is continuous in the file but represented in columns below): Kelly Brian Katie Michae Emily Jim John Jane Joe Doe Smith Hart Jones Hu Wright Young Green Hurley Write...

  • Can someone please code this problem in c++? Problem 1 You are to write a C++...

    Can someone please code this problem in c++? Problem 1 You are to write a C++ program to print the following design in the output window. (Note that * is an asterisk, which is commonly found above the 8 on a standard keyboard. On different terminal types, the asterisk may be rendered differently. You need not concern yourself with the appearance of the asterisk. When I run the program, as long as you have used the correct key on the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT