Python Stack Board Questions


  1. Consider a list named Nums which contains random integers. [3 MARKS] [2024]
    Write the following user defined functions in Python and perform the specified operations on a stack named BigNums.

    (i) PushBig() : It checks every number from the list Nums and pushes all such numbers which have 5 or more digits into the stack, BigNums.

    (ii) PopBig() : It pops the numbers from the stack, BigNums and displays them. The function should also display “Stack Empty” when there are no more numbers left in the stack.

    For example : If the list Nums contains the following data :
    Nums = [213, 10025, 167, 254923, 14,1297653, 31498, 386, 92765]

    Then on execution of PushBig(), the stack BigNums should store :
    [10025, 254923, 1297653, 31498, 92765]

    And on execution of PopBig(), the following output should be displayed :
    92765
    31498
    1297653
    254923
    10025
    Stack Empty
  2. coming soon

  3. Write a function in Python, Push(Vehicle) where, Vehicle is a dictionary containing details of vehicles – {Car_name : Maker}. [3 MARKS] [2023]

    The function should push the name of car manufactured by “TATA” (including all the possible cases like Tata, TaTa, etc) to the stack.

    For Example : 
    
    If the dictionary contains the following data : 
    Vehicle= {“Santro” : “Hyundai”, “Nexon” : “TATA”, “Safari” : “Tata”}
    
    The stack should contain
    Safari
    Nexon
    
  4. stack=[]
    def Push(Vehicle) :
          for v_name in Vehicle :
                if Vehicle[v_name].upper()=="TATA" :
                      stack.append(v_name)
    
    OR
    
    stack=[]
    def Push(Vehicle) :
          for v_name in Vehicle :
                if Vehicle[v_name] in ("TATA", "TaTa","tata","Tata"):
                      stack.append(v_name)
    

  5. A list contains following record of customer : [Customer_name, Room_Type] [3 MARKS] [2023]

    Write the following user defined functions to perform given operations on the stack named ‘Hotel’ :
    (i) Push_Cust( ) – To Push customers' names of those customers who are staying in ‘Deluxe’ Room Type.
    (ii) Pop_Cust( ) – To Pop the names of customers from the stack and display them. Also, display “Underflow” when there are no customers in the stack.

    For example : 
    
    If the lists with customer details are as follows : 
    [“Siddarth”, “Deluxe”]
    [“Rahul”, “Standard”]
    [“Jerry”, “Deluxe”]
    
    The stack should contain
    Jerry
    Siddarth
    
    The output will be : 
    Jerry
    Siddarth
    Underflow
    
  6. Hotel=[]
    Customer=[["Siddarth","Delux"],["Rahul","Standard"],["Jerry","Delux"]]
    
    def Push_Cust():
          for rec in Customer:
                if rec[1]=="Delux":
                      Hotel.append(rec[0])
    
    def Pop_Cust():
          while len(Hotel)>0:
                print(Hotel.pop())
          else:
                print("Underflow")