Question

Write statements to create a symmetric difference Write statements to issubset and issuperset Write statements to...

Write statements to create a symmetric difference

Write statements to issubset and issuperset

Write statements to clear a set

Write statements to find maximum and the minimum value in a set

Write statements to find the length of a set

python

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

SOURCE CODE:

an=int(input("Enter how many elements you want in set A: ")) #reading number of elements of A
bn=int(input("Enter how many elements you want in set B: ")) #reading number of elements of B
A=set() #creating empty set A
B=set() #creating empty set B
print("Enter elements of set A:-")
for i in range(an):
e=int(input()) #reading elements from user to A
A.add(e) #adding read element to A

print("Enter elements of set B:-")
for j in range(bn):
e=int(input()) #reading elements from user to B
B.add(e) #adding read element to B

print("\nA: ",A,"\tB: ",B) #printing A and B
#calculating symmetric_difference of A and B
print("\nSymmetric difference of A and B: ",A.symmetric_difference(B))
print("\nIs A subset of B? ",A.issubset(B)) #checking A is subset of B
print("Is B subset of A? ",B.issubset(A)) #checking B is subset of A


print("\nIs A superset of B? ",A.issuperset(B)) #checking A is superset of B
print("Is B superset of A? ",B.issuperset(A)) #checking B is superset of A


print("\nMaximum of set A is: ",max(A)) #finding max of A
print("Maximum of set B is: ",max(B)) #finding max of B

print("\nMinimum of set A is: ",min(A)) #finding min of A
print("Minimum of set B is: ",min(B)) #finding min of B


print("\nLength of set A: ",len(A)) #finding length of A
print("Length of set B: ",len(B)) #finding length of B


A.clear() #clearing set A
B.clear() #clearing set B


  
  

CODE SCREENSHOT:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write statements to create a symmetric difference Write statements to issubset and issuperset Write statements to...
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
  • Write a python program where you create a list (you an create it in code you...

    Write a python program where you create a list (you an create it in code you do not have to use input() statements) that represents the total rainfall for each of 12 months (assume that element 0 is January and element 11 is December). The program should calculate and display the: 1) total rainfall for the year; 2) the average monthly rainfall; 3) the months with the highest and lowest amounts. You need to figure out how to access each...

  • Write a program that prompts the user for two integers and then prints The sum The...

    Write a program that prompts the user for two integers and then prints The sum The difference The product The average The distance (absolute value of the difference) The maximum (the larger of the two) The minimum (the smaller of the two) hint: python defines max and min functions that accept a sequence of values, each separated with a comma. **program must be written in Python**

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • Create a file called Sort.py (note the capitalization). Within that file, write two different Python functions....

    Create a file called Sort.py (note the capitalization). Within that file, write two different Python functions. Each function will take an array of integers as a parameter and sort those integers in increasing order. One will use insertion sort, and the other will use selection sort (described below). Simple functions will suffice here; do not create any classes. Your insertion sort function should be called insertion_sort(arr). Your selection sort function should be called selection_sort(arr). Selection sort must use a while...

  • Write statements to remove spaces from dictionary keys Write statements to get the key, value and...

    Write statements to remove spaces from dictionary keys Write statements to get the key, value and item in a dictionary Write statements to replace dictionary values with their sum python

  • Write Python statements to create the following Python lists (to submit this, copy paste your answers):...

    Write Python statements to create the following Python lists (to submit this, copy paste your answers): I need help with these problems. 1. List of 5 or more colors 2. List of your friends on our college campus (first names ok) 3. List of first names of your family members 4. List of 5 or more grocery items that you need to purchase to prepare dinner tonight 5. List of the following characters: A, E, I, O, U

  • Define the symmetric difference of two sets to be S * T = (S ∪ T)...

    Define the symmetric difference of two sets to be S * T = (S ∪ T) \ (S ∩ T). Show that the power set P(S) is a vector space over Z2 with addition given by *.

  • Write a Python program that uses a tuple. Create a tuple of your matric subjects. The...

    Write a Python program that uses a tuple. Create a tuple of your matric subjects. The program must display the first element, the last element, and the length of the tuple. An explanation message should also be included. E.g. The length of the tuple is 4. The user needs to be prompted for a subject, and the code needs to find the subject in the tuple. The user needs to be informed whether or not the subject is included in...

  • Exercise 3.2 (Symmetric and Asymmetric Encryption) t In this exercise, you will send an encrypted...

    Exercise 3.2 (Symmetric and Asymmetric Encryption) t In this exercise, you will send an encrypted message from a socket client to a socket server. The message will be encrypted using AES symmetric encryption algorithm in the client. The server receives this ciphertext and decrypt it using the same symmetric key. Before communication over symmetric encryption, you need to first securely distribute the symmetric key between sender and receiver. You can use asymmetric encryption to help distribute the symmetric key. The...

  • Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right...

    Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right triangle whose other two sides have lengths a and b The value of the expression that evaluates whether the length of the above hypotenuse is 5 The area of a disk of radius a The value of the Boolean expression that checks whether a point with coordinates x and y is inside a circle with center (a, b) and radius r

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