0% found this document useful (0 votes)
4 views4 pages

Stack 1

The document contains a Python script that implements stack operations and student record management. It allows users to add (push), remove (pop), and display elements in a stack, as well as manage student records by adding, deleting, and displaying student information. The script runs in a loop, providing a menu for user interaction until the exit option is selected.

Uploaded by

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

Stack 1

The document contains a Python script that implements stack operations and student record management. It allows users to add (push), remove (pop), and display elements in a stack, as well as manage student records by adding, deleting, and displaying student information. The script runs in a loop, providing a menu for user interaction until the exit option is selected.

Uploaded by

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

stack = []

def push():
element = input("Enter element to add (push): ")
[Link](element)
print(f"{element} added to stack.")

def pop_element():
if len(stack) == 0:
print("Stack is empty! Nothing to remove.")
else:
element = [Link]()
print(f"Removed element: {element}")

def show():
if len(stack) == 0:
print("Stack is empty.")
else:
print("Current Stack:")
for i in range(len(stack) - 1, -1, -1):
print(stack[i])

while True:
print("\nSTACK OPERATIONS MENU")
print("1. Add (Push)")
print("2. Remove (Pop)")
print("3. Show Stack")
print("4. Exit")

choice = input("Enter your choice (1-4): ")

if choice == '1':
push()
elif choice == '2':
pop_element()
elif choice == '3':
show()
elif choice == '4':
print("Stack operations completed.")
break
else:
print("Invalid choice! Please enter a number between 1 and 4.")
host=[]
ch='y'
def push(host):
rno=int(input("Enter Student Roll Number"))
name=input("Enter Student Name")
city=input("Enter City")
temp=[rno,name,city]
[Link](temp)
def pop(host):
if(host==[]):
print("No Record")
else:
print("Deleted Record is:",[Link]())
def display(host):
l=len(host)
print("Student Roll Number\t Student Name")
for i in range(l-1,-1,-1):
print(host[i])

while(ch=='y' or ch=="Y"):
print("1. Add Record\n")
print("2. Delete Record\n")
print("3. Display Record\n")
print("4. Exit")
op=int(input("Enter the Choice"))
if(op==1):
push(host)
elif(op==2):
pop(host)
elif(op==3):
display(host)
elif(op==4):
break

You might also like