def difference_list(self): while 1: print("---------------------------------------------------") print("1.Create List" "\n" "2. Calculate difference b/w lists" "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create1 = UtilityDS.create_list(element) print("List 2 create : ") self.create2 = UtilityDS.create_list(element) print("List is created : ", self.create2) elif choice == 2: # if list is empty if len(self.create1) == 0 or len(self.create2) == 0: if len(self.create1) < 1: print("please create list 1") elif len(self.create2) < 1: print("please create list 2") else: print("List are empty..create list first.") # if list in not empty then display difference b/w list else: diff = UtilityDS.get_diff_list( self.create1, self.create2) print("difference in lists : ", diff) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def multiply_list(self): while 1: print("1.Create List" "\n" "2.Multiplication of element " "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list create = UtilityDS.create_list(element) print("List is created : ", create) elif choice == 2: # display sum of the list element mul_list = UtilityDS.multiplication_list(create) print("Multiplication of items : ", mul_list) elif choice == 3: # exit from program exit() except Exception as e: print(e)
def sum_list(self): while 1: print("1.Create List""\n""2.Sum of list""\n""3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list ") # number of element to add element = int(input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create = UtilityDS.create_list(element) print("List is created : ", self.create) elif choice == 2: if len(self.create) < 1: print("create list first") else: # display sum of the list element sum_list = UtilityDS.sum_list(self.create) print("Sum of list : ", sum_list) elif choice == 3: # exit from program exit() except Exception as e: print(e)
def common_member(self): while 1: print("---------------------------------------------------") print("1.Create List" "\n" "2. Get common member N" "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create1 = UtilityDS.create_list(element) print("creating list 2:") self.create2 = UtilityDS.create_list(element) print("List 1 is created : ", self.create1) print("List 2 is created : ", self.create2) elif choice == 2: # if list is empty if len(self.create1) == 0 or len(self.create2) == 0: if len(self.create1) < 1: print("please create list 1") elif len(self.create2) < 1: print("please create list 2") else: print("List are empty..create list first.") # if list in not empty , display list of word longer than Num else: common = UtilityDS.common_member( self.create1, self.create2) print("Common members are : ", common) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def duplicate(self): while 1: print("---------------------------------------------------") print("1.Create List""\n""2. Remove Duplicates ""\n""3.view list""\n""4.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int(input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create = UtilityDS.create_list(element) print("List is created : ", self.create) elif choice == 2: # if list is empty if len(self.create) == 0: print("List is empty..create list first.") # if list in not empty then display list after removal of duplicate else: remove = UtilityDS.remove_duplicate(self.create) print("After removing duplicate : ", remove) elif choice == 3: # view list print("List is : ", self.create) elif choice == 4: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def difference_list(self): while 1: print("---------------------------------------------------") print("1.Create List" "\n" "2. Perform circular identical on lists" "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create1 = UtilityDS.create_list(element) print("create List 2 ----------- : ") self.create2 = UtilityDS.create_list(element) print("create List 3 ----------- :") self.create3 = UtilityDS.create_list(element) print("List 1 : ", self.create1) print("List 2 : ", self.create2) print("List 3 : ", self.create3) elif choice == 2: # if list is empty if len(self.create1) == 0 or len(self.create2) == 0: if len(self.create1) < 1: print("please create list 1") elif len(self.create2) < 1: print("please create list 2") else: print("List are empty..create list first.") # if list in not empty then display whether lists are circular identical else: compare1 = UtilityDS.circular_identical( self.create1, self.create2) print( "Circular identical with List 1 & List 2 : ", compare1) compare2 = UtilityDS.circular_identical( self.create1, self.create3) print( "Circular identical with List 1 & List 3 : ", compare2) compare3 = UtilityDS.circular_identical( self.create1, self.create3) print( "Circular identical with List 2 & List 3 : ", compare3) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)