def push():
key=int(input("Enter a key in number :"))
value=input("Enter a value in words :")
stack[key]=value
print("Element added successfully\n")
def pop():
if stack=={}:
print("Stack is empty\n")
else:
print("Deleted element is",stack.popitem())
print()
def peek():
if stack=={}:
print("Stack is empty-No top element\n")
else:
L=list(stack.keys())
lastkey=L[-1]
print("Top element is",lastkey,"----",stack[lastkey])
print()
def display():
if stack=={}:
print("Stack is empty\n")
else:
print("The stack is :")
L=list(stack.keys())
L.reverse()
for i in L:
print(i,"----",stack[i])
print()
#__main__
stack={}
while True:
print("STACK OPERATIONS")
print("1. Push")
print("2. Pop")
print("3. Peek")
print("4. Display Stack")
print("5. Exit")
choice=int(input("Enter your choice\n"))
if choice==1:
push()
elif choice==2:
pop()
elif choice==3:
peek()
elif choice==4:
display()
elif choice==5:
print("Thank You!!!")
break
else:
print("Choice must be between 1-5\n")
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
4
Stack is empty
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
1
Enter a key in number :5
Enter a value in words :five
Element added successfully
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
1
Enter a key in number :9
Enter a value in words :nine
Element added successfully
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
1
Enter a key in number :3
Enter a value in words :three
Element added successfully
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
4
The stack is :
3 ---- three
9 ---- nine
5 ---- five
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
3
Top element is 3 ---- three
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
2
Deleted element is (3, 'three')
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
4
The stack is :
9 ---- nine
5 ---- five
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display Stack
5. Exit
Enter your choice
5
Thank You!!!