Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

PART I Python Programming : 08 marks

Logic 5 marks, Documentation 1 ½ marks and Code quality 1 ½ marks


PART II MYSQL : 04 marks
PART III Report File : 07 marks
PART IV Project : 08 marks
PART V Viva Voce : 03 marks

STACKS
SET 1

PART I : LAB TEST- 1: (Python Programming: 8 marks)


Logic: 5 marks Documentation: 1 ½ marks Code quality: 1 ½ marks
Using user defined functions, write a Menu Based Program to implement a stack where each
node holds details of doctors. Take care of overflow/underflow situations. The Menu should
be:
1. Push
2. Pop
3. Display entire stack content.
4. Exit
Each node of the Stack will have the following structure:
(DOCID, NAME,DEPARTMENT)

def Push(data):
global top
#insert the element on the top of the stack
Stack.append(data)
top=top+1 #points to the last element inserted into the
stack
def Pop():
global top
if Stack==[]: #there are no elements in the stack
print("UNDERFLOW")
else:
item=Stack.pop() # delete the element on the top of
the stack or last element inserted
top=top-1 #holds the index of the last element
print("\nPOPPED ITEM IS :", item)
def Peek():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:
print("THE ELEMENT ON THE TOP OF STACK
IS:",Stack[top]) #The element pointed to by top
def Display():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:
print("\n\t\tTHE STACK CONTENT\n")
print("DOCID", "NAME", "DEPARTMENT")
print("__________________________________")
for i in range(top,-1,-1): #printing elements from
the top to the first element inserted
print(Stack[i])

#initially stack is empty


Stack=[] #EMPTY LIST
top=-1
while True:
print("\n\t\tSTACK OPERATIONS")
print("_________________________________________")
print("\t\t1:PUSH")
print("\t\t2:POP")
print("\t\t3:DISPLAY ENTIRE STACK CONTENT")
print("\t\t4:DISPLAY TOP NODE")
print("\t\t5:EXIT")
ch=int(input("\nENTER YOUR CHOICE (1-5):"))
if ch==1:
data=[]
DOCID=int(input("Enter the doctor id:"))
NAME=input("Enter the name:")
DEPARTMENT=input("Enter the department: ")
data=(DOCID,NAME,DEPARTMENT)
Push(data)
elif ch==2:
Pop()
elif ch==3:
Display()
elif ch==4:
Peek()
elif ch==5:
break
else:
print("INVALID")
SET 7

PART I : LAB TEST- 1: (Python Programming: 8 marks)


Logic: 5 marks Documentation: 1 ½ marks Code quality: 1 ½ marks

Using user defined functions, write a Menu Based Program to implement a stack where each
node holds details of players. Take care of overflow/underflow situations. The Menu should
be:
1. Push
2. Pop
3. Display entire stack content.
4. Exit
Each node of the Stack will have the following structure:
{'name':_____, 'points': ______}
def Push(data):
global top
if len(Stack)==size:
print("OVERFLOW")
else:
#insert the element on the top of the stack
Stack.append(data)
top=top+1 #The last element inserted into the stack

def Pop():
global top
if Stack==[]: #there are no elements in the stack
print("UNDERFLOW")
else:
item=Stack.pop() # delete the element on the top of
the stack
top=top-1 #holds the index of the last element
print("\nPOPPED ITEM IS :", item)

def Display():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:
print("\n\t\tTHE STACK CONTENT\n")
print("NAME", "POINTS")
print("__________________________________")
for i in range(top,-1,-1): #printing elements from
the top to the first element inserted
print(Stack[i])
#initially stack is empty
Stack=[] #EMPTY LIST
top=-1
size=5
while True:
print("\n\t\tSTACK OPERATIONS")
print("_________________________________________")
print("\t\t1:PUSH")
print("\t\t2:POP")
print("\t\t3:DISPLAY ENTIRE STACK CONTENT")
print("\t\t4:DISPLAY TOP NODE")
print("\t\t5:EXIT")
ch=int(input("\nENTER YOUR CHOICE (1-5):"))
if ch==1:
data={}
data['name'] = input("name:")
data['points'] = int(input("Enter points:"))
Push(data)
elif ch==2:
Pop()
elif ch==3:
Display()
elif ch==4:
break
else:
print("INVALID CHOICE!!")
PART I : LAB TEST- 1: (Python Programming: 8 marks)
Logic: 5 marks Documentation: 1 ½ marks Code quality: 1 ½ marks

Using user defined functions, write a Menu Based Program to implement a stack that
holds details of books. Take care of overflow/underflow situations. The Menu should be
1. Push
2. Pop
3. Display entire stack content
4. Display Top Node
5. Exit
Each node of the Stack will have the following structure
[BOOK_ID, TITLE, AUTHOR, PRICE]

def Push(data):
global top
#insert the element on the top of the stack
Stack.append(data)
top=top+1 #points to the last element inserted into the stack

def Pop():
global top
if Stack==[]: #there are no elements in the stack
print("UNDERFLOW")
else:
item=Stack.pop() # delete the element on the top
top=top-1 #holds the index of the last element
print("\nPOPPED ITEM IS :", item)

def Peek():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:
print("THE ELEMENT ON THE TOP OF STACK IS:",Stack[top])
#prints the element pointed to by top

def Display():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:

print("\n\t\tTHE STACK CONTENT\n")


print("BOOK_ID", "TITLE", "AUTHOR", "PRICE")
print("__________________________________")
for i in range(top,-1,-1): #prints from top to first
print(Stack[i])

#initially stack is empty


Stack=[] #EMPTY LIST
top=-1
while True:
print("\n\t\tSTACK OPERATIONS")
print("_________________________________________")
print("\t\t1:PUSH")
print("\t\t2:POP")
print("\t\t3:DISPLAY ENTIRE STACK CONTENT")
print("\t\t4:DISPLAY TOP NODE")
print("\t\t5:EXIT")
ch=int(input("\nENTER YOUR CHOICE (1-5):"))
if ch==1:
data=[]
BOOK_ID=int(input("Enter the book id:"))
TITLE=input("Enter the title:")
AUTHOR=input("Enter the Author details: ")
PRICE=float(input("Enter the price"))
data=[BOOK_ID, TITLE, AUTHOR, PRICE]
Push(data)
elif ch==2:
Pop()
elif ch==3:
Display()
elif ch==4:
Peek()
elif ch==5:
break
else:
print("INVALID CHOICE!!")
PART I : LAB TEST- 1: (Python Programming: 8 marks)
Logic: 5 marks Documentation: 1 ½ marks Code quality: 1 ½ marks
Using user defined functions, write a Menu Based Program to implement a stack where each
node holds details of Trains. Take care of overflow/underflow situations. The Menu should
be:
1. Push
2. Pop
3. Display entire stack content.
4. Exit
Each node of the Stack will have the following structure:
(TrainNo, Distance)
def Push(data):
global top
#insert the element on the top of the stack
Stack.append(data)
top=top+1 #points to the last element inserted into the stack

def Pop():
global top
if Stack==[]: #there are no elements in the stack
print("UNDERFLOW")
else:
item=Stack.pop() # deletes the element on the top
top=top-1 #holds the index of the last element
print("\nPOPPED ITEM IS :", item)

def Peek():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:
print("THE ELEMENT ON THE TOP OF STACK IS:",Stack[top])
#prints the element pointed to by top

def Display():
global top
if Stack==[]:
print("UNDERFLOW!STACK IS EMPTY!!")
else:

print("\n\t\tTHE STACK CONTENT\n")


print("TrainNo", "Distance")
print("__________________________________")
for i in range(top,-1,-1): #printing from top to first
print(Stack[i])
#initially stack is empty
Stack=[] #EMPTY LIST
top=-1
while True:
print("\n\t\tSTACK OPERATIONS")
print("_________________________________________")
print("\t\t1:PUSH")
print("\t\t2:POP")
print("\t\t3:DISPLAY ENTIRE STACK CONTENT")
print("\t\t4:DISPLAY TOP NODE")
print("\t\t5:EXIT")
ch=int(input("\nENTER YOUR CHOICE (1-5):"))
if ch==1:
data=[]
TrainNo=int(input("Enter the train No:"))
Distance=float(input("Enter the distance:"))
data= (TrainNo, Distance)
Push(data)
elif ch==2:
Pop()
elif ch==3:
Display()
elif ch==4:
Peek()
elif ch==5:
break
else:
print("INVALID CHOICE!!")

You might also like