Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- GROUP 2
- ABREU, TRISTAN
- DALMACIO, RODGE
- ORTIZ, LM
- '''
- import time
- import sys
- # clear output screen
- def clear_screen():
- print('\033c', end='')
- # typewriting printing animation
- def typewriting_anim(text):
- for char in text:
- sys.stdout.write(char)
- sys.stdout.flush()
- time.sleep(0.10)
- # to add a element in the corresponding chosen set
- def set_element_adder(state_set, set_message):
- while len(state_set) <= 4:
- print(f"\n{set_message}\n\nSET A: {A}\nSET B: {B}\n")
- try:
- add_element = int(input("Enter a element for this set: "))
- # check for duplicates in the set
- if add_element in state_set:
- clear_screen()
- typewriting_anim("This element is already in the set. Please enter a different element... ")
- clear_screen()
- continue
- state_set.add(add_element)
- add_choice = input("Successfully added! Add another element? [Y/N]: ").capitalize()
- if add_choice == "Y":
- clear_screen()
- continue
- elif add_choice == "N":
- clear_screen()
- break
- else:
- clear_screen()
- typewriting_anim("Invalid choice. Please choose Y or N... ")
- clear_screen()
- continue
- except ValueError:
- clear_screen()
- typewriting_anim("An error has occurred. Please try again... ")
- clear_screen()
- continue
- else:
- typewriting_anim("Maximum has been reached for this set... ")
- clear_screen()
- # set declaration
- A = set()
- B = set()
- set_a_message = "Add elements for SET A (MAXIMUM IS 5):"
- set_b_message = "Add elements for SET B (MAXIMUM IS 5):"
- clear_screen()
- set_element_adder(A, set_a_message)
- set_element_adder(B, set_b_message)
- clear_screen()
- # determine the conditions for Q1, Q2, and Q3
- is_equal = A == B
- is_equivalent = len(A) == len(B)
- is_both = is_equal and is_equivalent
- # print the final results
- print(f"""\n
- A = {A}
- B = {B}
- Q1. Are the 2 sets equal? {is_equal}
- Q2. Are the 2 sets equivalent? {is_equivalent}
- Q3. Are the 2 sets both equal and equivalent? {is_both}
- """)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement