Advertisement
xi_arma

YAURRRRRRRRRRRRRRRRRRRR

Aug 13th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. '''
  2. GROUP 2
  3. ABREU, TRISTAN
  4. DALMACIO, RODGE
  5. ORTIZ, LM
  6. '''
  7.  
  8. import time
  9. import sys
  10.  
  11. # clear output screen
  12. def clear_screen():
  13.     print('\033c', end='')
  14.  
  15. # typewriting printing animation
  16. def typewriting_anim(text):
  17.     for char in text:
  18.         sys.stdout.write(char)
  19.         sys.stdout.flush()
  20.         time.sleep(0.10)
  21.  
  22. # to add a element in the corresponding chosen set
  23. def set_element_adder(state_set, set_message):
  24.     while len(state_set) <= 4:
  25.         print(f"\n{set_message}\n\nSET A: {A}\nSET B: {B}\n")
  26.         try:
  27.             add_element = int(input("Enter a element for this set: "))
  28.            
  29.             # check for duplicates in the set
  30.             if add_element in state_set:
  31.                 clear_screen()
  32.                 typewriting_anim("This element is already in the set. Please enter a different element...  ")
  33.                 clear_screen()
  34.                 continue
  35.            
  36.             state_set.add(add_element)
  37.             add_choice = input("Successfully added! Add another element? [Y/N]: ").capitalize()
  38.             if add_choice == "Y":
  39.                 clear_screen()
  40.                 continue
  41.             elif add_choice == "N":
  42.                 clear_screen()
  43.                 break
  44.             else:
  45.                 clear_screen()
  46.                 typewriting_anim("Invalid choice. Please choose Y or N...   ")
  47.                 clear_screen()
  48.                 continue
  49.         except ValueError:
  50.             clear_screen()
  51.             typewriting_anim("An error has occurred. Please try again...  ")
  52.             clear_screen()
  53.             continue
  54.        
  55.     else:
  56.         typewriting_anim("Maximum has been reached for this set...   ")
  57.         clear_screen()
  58.  
  59. # set declaration        
  60. A = set()
  61. B = set()
  62.  
  63. set_a_message = "Add elements for SET A (MAXIMUM IS 5):"
  64. set_b_message = "Add elements for SET B (MAXIMUM IS 5):"
  65.  
  66. clear_screen()
  67. set_element_adder(A, set_a_message)
  68. set_element_adder(B, set_b_message)
  69. clear_screen()
  70.  
  71. # determine the conditions for Q1, Q2, and Q3
  72. is_equal = A == B
  73. is_equivalent = len(A) == len(B)
  74. is_both = is_equal and is_equivalent
  75.  
  76. # print the final results
  77. print(f"""\n
  78. A = {A}
  79. B = {B}
  80.  
  81. Q1. Are the 2 sets equal? {is_equal}
  82. Q2. Are the 2 sets equivalent? {is_equivalent}
  83. Q3. Are the 2 sets both equal and equivalent? {is_both}
  84. """)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement