English

Write a function in Python, Push(SItem) where SItem is a dictionary containing the details of stationery items - {Sname:price}. The function should push the names of those items in the stack - Computer Science (Python)

Advertisements
Advertisements

Question

Write a function in Python, Push(SItem) where SItem is a dictionary containing the details of stationery items - {Sname:price}. The function should push the names of those items in the stack that have a 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

Short Note

Solution

stackItem=[]
def Push(SItem):
     count=0
     for k in SItem:
            if (STtem[k]>=75):
                 stackItem.append (k)
                 count=count+1
     print("The count of elements in the stack is : ",count)
shaalaa.com
  Is there an error in this question or solution?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×