def Company_Shares(): global user st = Stock("stock_json") # object is created for stock and linked list llist = LinkedList() with open("stock_json") as f: # json file is loaded data = json.load(f) for items in data: # json file is converted in linked list llist.Add(items) # input is taken from the user while True: try: # try is used for the finding exception for i in range(len(st.Only_Stocks())): # will display all the stocks in the portfolio print("**", st.Only_Stocks()[i], end=" ") print("\nchoose from above stocks to delete stocks ") user = int(input("enter 1 to add or enter 2 to delete or enter 3 to exit :")) if user >= 4 or user <= 0: print("check input") continue if user == 1: llist.Add(st.Buy()[1]) # if user is given 1 we will ad the stock to the linked list llist.Print() elif user == 2: g = st.Sell() # if user is given 2 we will call stock class to delete the data llist.Remove(data[g]) # here data is removed print("stock is removed") else: print("bye bye") # program will end here st.Dump("stock_json") break except ValueError: print(" please check the Value Error ")
def UnorderedlList(): # new function for linked list items = ReadFile("numbers") llist = LinkedList() try: # try exception is used for the finding the error for data in items: # data is added and printed in linked list format llist.Add(data) except AttributeError: # error is caught if any print("please check the error ") llist.Print()
def Anagram_Queue(): # function created llist = LinkedList() # object is created q = Queue1() anagram = PrimeAnagram() try: # try catch is used to catch error if error for data in anagram: q.AddRear( llist.Add(data) ) # add rear function is used and data is added via linked list llist.Print() # q.PrintList() # if we print queue we will data in none as linked list data type is None except AttributeError: print("check the class file for error")
def Anagram_Reversed(): # function created llist = LinkedList() # object is created stack = Stack() anagrams = PrimeAnagram() try: # try exception is used for the finding the error for data in anagrams[::-1]: stack.Push( llist.Add(data) ) # push function is used and data is pushed via linked list llist.Print() # print(stack.size()) # if we print stack we will data in none as linked list data type is None except AttributeError: # if error found exception is print the below statement print("please check class file ")
class Queue1: """ queue called is created with different attribution """ def __init__( self ): # queue is used for linked list as linked list is called in queue self.ul = LinkedList() self.items = [] def Dequeue(self): # de-queue is used for popping data from queue self.items.pop() def AddRear( self, data): # add gear is used for adding data at the end for the array self.items.insert(0, data) return self.ul.Add(data) def AddFront( self, data): # add front is used for adding adding in front of the queue self.items.append(data) return self.ul.Add(data) def RemoveRear(self): # remove function is used removing data from rear return self.items.pop(0) def RemoveFront( self ): # remove front is used or removing data from front of the array return self.items.pop() def IsEmpty(self): # is empty is used for empty the function return self.items == [] def Size( self): # size function is used for checking the length of the data print(len(self.items)) def PrintList(self): # print list is used for printing function # print(self.items) self.ul.Print() def QueueList( self): # queue list is used for returning the items from the list return self.items
def HashingFile(): # hashing function is used for hashing the file hash = Hashing() # object is created for the class llist = LinkedList() it = ReadFile("key") # data is read from the file data = [] # file data is iterated below and appended in the data array for i in it: data.append(int(i)) # print(data) try: # try function is used for catching the exceptions to handle exceptions for i in data: # we have added data in hash table by calling insert function hash.Insert(i) for i in hash.Print(): # now hash file is add to the liked list llist.Add(i) # print(hash.print()) # hash table will print llist.Print() # now linked list from hash table will be printed except AttributeError: # if any error it will below statement print("please check the class file ")
def Company_Shares(): global add, remove st = Stock("stock_json") # object is created for stock and linked list llist = LinkedList() stack = Stack() q = Queue1() with open("stock_json") as f: # json file is loaded data = json.load(f) while True: try: # try is used for the finding exception userinput = int( input("number of stocks you want to Buy or Sell : ")) if userinput >= 5 or userinput <= 0: print("user input should be between 0-5") continue for i in range(userinput): # input is taken from the user for stocks in range(len(st.Only_Stocks())): print(st.Only_Stocks()[stocks], end="--" ) # will display all the stocks in the portfolio while True: user = int( input( "\nenter 1 to add \nenter 2 to delete \nenter 3 to exit :" )) if user >= 4 or user <= 0: print("enter between 0-4") continue break if user == 1: added = st.Buy()[1] stack.Push(added) print() llist.Add( stack.Size()[0]["stock"] ) # if user is given 1 we will ad the stock to the linked list now = datetime.datetime.now() q.AddRear(now) elif user == 2: remove = st.Sell() stack.Push(data[remove]) llist.Add(stack.Size()[0]["stock"]) now1 = datetime.datetime.now() q.AddRear(now1) else: print("bye bye") # program will end here llist.Print( ) # final linked list is printed with the symbol which were added o removed print() q.PrintList( ) # final linked list is printed from queue function where time stamp of the add or remove is # updated st.Dump( "stock_json" ) # this method is used for appending the data in JSON format break except (ValueError, TypeError): print(" please check the Error ")