コード例 #1
0
def Palindrome(string1):
    while True:
        q = Queue1()
        string1_list = list(
            string1
        )  # converting string into list for checking with queue list
        print(string1_list)  # printing list to double check
        # for loop is used to iterate the function and add items to rear of the list
        try:  # try catch function is use for the error if any

            for i in range(len(string1_list)):
                q.AddRear(string1_list[i])

            q.PrintList()  # list is printed to check
            # print(q.queuelist())

            if q.QueueList(
            ) == string1_list:  # this if condition is used to compare both list  and give out results
                print("its a palindrome")
            else:
                print("its not a palindrome")

            break
        except ValueError:
            print("check the input data")
コード例 #2
0
def Calender_Using_Linked_List():  # function is created
    while True:
        try:
            llist = LinkedList()  # object is created for imported classes
            q = Queue1()
            month = int(input("which month's calender u wish to see in MM format :"))
            if month <= 0 or month >= 13:
                print("enter between 0 and 13")
                continue

            year = int(input("for which year YYYY format"))
            if year <= 1000 or year >= 3000:
                print("enter between 1000 and 3000")
                continue

            array = Calender(month, year)
            # try is used for locating the error
            for items in array:  # for loop is used using adding data in linked list
                for data in items:
                    q.AddRear(llist.Add(data))  # data is added in the linked list via queue class

            llist.PrintCalendar()  # now calendar is printed in linked list
            break

        except ValueError:  # exception will find the error
            print("please check the input ")
コード例 #3
0
ファイル: card_game.py プロジェクト: nk900600/Bridge-Labz1
def Playing_Card():

    Que = Queue1()
    cards = CardGame()  # object is created for card game
    data = cards.Distribute()  # distribute function is called from card game and results will be printed in 2d array
    # print(data)   # distributed card will be printed out
    for hand in range(len(data)):  # for loop is used for adding each players cards to the linked list
        data[hand].sort()
        Que.AddRear(data[hand])
    # hands are updated to the queue via linked list
    print()
    Que.PrintList()     # same distributed cards are printed out in linked list format in queue
コード例 #4
0
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")
コード例 #5
0
    def test_anagram_queue(self):  # test_ function is made

        q = Queue1()  # queue is imported
        ana = Anagram_Queue()  # here function is stored in var
        self.assertEqual(ana, q.Size())  # here we validated the program
コード例 #6
0
 def test_palindrome(self):
     q = Queue1()  # queue function is created
     palind = Palindrome("nik")
     self.assertEqual(palind, q.Size())  # here we will compare the error
コード例 #7
0
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 ")