Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
16.5k views
in Computer by (38.9k points)
closed by

Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a program, with separate user defined functions to perform the following operations:

● Push the keys (name of the student) of the dictionary into a stack, where the corresponding value (marks) is greater than 75.

● Pop and display the content of the stack.

For example: 

If the sample content of the dictionary is as follows:

R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}

The output from the program should be: 

TOM ANU BOB OM

OR 

Alam has a list containing 10 integers. You need to help him create a program with separate user defined functions to perform the following operations based on this list. 

● Traverse the content of the list and push the even numbers into a stack. 

● Pop and display the content of the stack.

For Example: 

If the sample Content of the list is as follows:

 N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]

Sample Output of the code should be: 

38 22 98 56 34 12

1 Answer

+2 votes
by (36.7k points)
selected by
 
Best answer

(first option) 

R={"OM":76, "JAI":45, "BOB":89, 

"ALI":65, "ANU":90, "TOM":82} 

def PUSH(S,N): 

   S. append(N) 

def POP(S): 

   if S!=[]: 

   return S.pop() 

else: 

     return None 

ST=[ ] 

for k in R: 

       if R[k]>=75: 

           PUSH(ST,k) 

while True: 

    if ST!=[ ]: 

        print(POP(ST),end=" ") 

else: 

   break

OR

(second option)

N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38] 

def PUSH(S,N):

   S. append(N) 

def POP(S): 

   if S!=[ ]: 

    return S.pop() 

else: 

   return None 

ST=[ ] 

for k in N: 

  if k%2==0: 

     PUSH(ST,k) 

while True: 

    if ST!=[ ]: 

       print(POP(ST),end=" ") 

else: 

  break

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...