Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_sets(set_A, set_B):
- # If the 2 sets are equal
- if set_A == set_B:
- Q1 = "Yes"
- else:
- Q1 = "No"
- # If the 2 sets are equivalent
- if len(set_A) == len(set_B):
- Q2 = "Yes"
- else:
- Q2 = "No"
- # If the 2 sets are both equal and equivalent
- if set_A == set_B and len(set_A) == len(set_B):
- Q3 = "Yes"
- else:
- Q3 = "No"
- return Q1, Q2, Q3
- def input_value_set(prompt):
- while True:
- user_input = input(prompt)
- values = user_input.split()
- # Check duplicate elements
- if len(values) != len(set(values)): # python removes duplicate elements. therefore, this function compares the length of what the user inputted and the set where python deletes the duplicate
- print("You have entered duplicate elements. Please try again.\n")
- continue
- if len(values) > 5:
- print("Maximum is 5 elements! Please try again.\n")
- else:
- try:
- return set(map(int, values))
- except ValueError:
- print("Invalid input. Please enter only integers separated by spaces.\n")
- # Get input from the user and create sets
- set_A = input_value_set("Enter integer values for SET A (separated by spaces): ")
- set_B = input_value_set("Enter integer values for SET B (separated by spaces): ")
- Q1, Q2, Q3 = check_sets(set_A, set_B)
- print(f"""
- A = {set_A}
- B = {set_B}
- Q1. Are the 2 sets equal? {Q1}
- Q2. Are the 2 sets equivalent? {Q2}
- Q3. Are the 2 sets both equal and equivalent? {Q3}
- """)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement