Write a function in Python, Push(SItem) where , SItem is a dictionary containing the details of stationary items– {Sname:price}.

The function should push the names of those items in the stack who have price greater than 75. Also display the count of elements pushed into the stack.

For example:

If the dictionary contains the following data:

Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}

 

The stack should contain

Notebook

Pen

The output should be:

The count of elements in the stack is 2

 

Answer:

stack_items=[ ]

def Push (SItem): 

    count= 0

    for i in SItem:

        if SItem[i]>= 75 :

            stack_items.append(i)

            count=count+ 1

    print( "The count of items in the stack: " ,count)

Slide5.JPG

Remove Ads
Teachoo · Class 12 Explore Class 12
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.