Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

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

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.