Python 26 stack
Python 26 stack
#Python26 Stack
max = 5
stack = []
x=0
def Menu():
global choice
global x
print("====Menu====")
print("1.Add a record")
print("2.Delete a record")
print("3.Display List")
print("4.Quit")
choice = int(input("Enter your choice:"))
def Addrecord():
global x
global stack
global max
if len(stack) < max:
name = str(input(("Enter a name:")))
stack[:0] = [name]
print(name, "is added.")
else:
print("The stack is full. You cannot add any record")
def Deleterecord():
global x
global stack
global max
if len(stack) > 0:
f = open("DataFile.txt", "w")
stack.pop(len(stack)-1)
print("A record is deleted")
else:
print("The stack is empty. You cannot delete any record.")
def Displaylist():
print(*stack, sep="\n")
def OpenFile():
f = open("DataFile.txt", "w")
def SaveFile():
f = open("DataFile.txt", "r")
f.close()
OpenFile()
while 1 == 1:
Menu()
if choice == 1:
Addrecord()
elif choice == 2:
Deleterecord()
elif choice == 3:
Displaylist()
elif choice == 4:
SaveFile()