0% found this document useful (0 votes)
9 views3 pages

Problem Statement 1

The document outlines a Python program that manages a stack of student names based on their marks. It includes functions to push names into the stack if their marks are greater than 75, pop names from the stack, and display the stack contents. The program features a menu for user interaction to perform these operations.

Uploaded by

hanshidel09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Problem Statement 1

The document outlines a Python program that manages a stack of student names based on their marks. It includes functions to push names into the stack if their marks are greater than 75, pop names from the stack, and display the stack contents. The program features a menu for user interaction to perform these operations.

Uploaded by

hanshidel09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Problem Statement: Create a dictionary containing names and

marks as key-value pairs of 6 students. Write a MENU BASED Python


program, with separate user-defined functions, to perform the
following:
1. Push the keys (names of the students) into a stack, where the
corresponding value (marks) is greater than 75.
2. Pop and display the contents of the stack.
Example:
If the dictionary is:
R = {"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
Then the program output should be:
TOM ANU BOB OM

Code:
R = {}
stack = []
MAX = 5

def push():
if len(stack) >= MAX:
print("Stack Overflow")
else:
name = input("Enter student name: ")
marks = int(input("Enter marks: "))
R[name] = marks
if marks > 75:
[Link](name)
print("Pushed into stack")
else:
print("Marks not greater than 75, not pushed")

def pop():
if len(stack) == 0:
print("Stack Underflow")
else:
print("Popped element:", [Link]())

def display():
if len(stack) == 0:
print("Stack Empty")
else:
print("Stack contents:")
print(stack[::-1])

def menu():
while True:
print("\n1. Push Element")
print("2. Pop Element")
print("3. Display Stack")
print("4. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
push()
elif ch == 2:
pop()
elif ch == 3:
display()
elif ch == 4:
break
else:
print("Invalid choice!")
menu()

Output:

You might also like