Professional Documents
Culture Documents
Sujalreport
Sujalreport
st=[]
def push():
print("-----ADD student Name-----")
y='y'
while y=='y':
name=input("Enter student name:")
st.append(name)
y=input("do you want to add more name(y/n):")
def pop():
if st==[]:
print("stack is empty")
else:
print("deleted name:",st.pop())
print(st)
def sdis():
if st==[]:
print("stack is empty")
else:
ln=len(st)
for i in range(ln-1,-1,-1):
print(st[i])
2.Program that receives two numbers in a function and returns the results of
all arithmetic operations (+,-,*,/,%) on these numbers.
def arcalc(x,y):
return x+y,x-y,x*y,x/y,x%y
#__main__
num1=int(input("enter number 1:"))
num2=int(input("enter number 2:"))
add,sub,mul,div,mod=arcalc(num1,num2)
print("Addition of given numbers:",add)
print("Subtraction of given numbers:",sub)
print("Product of given numbers:",mul)
print("Division of given numbers:",div)
print("Modulo of given numbers:",mod)
#####FUNCTIONS#####
def isempty(stack):
if stack==[]:
return True
else:
return False
def Push(stack,item):
global top
stack.append(item)
top=len(stack)-1
def Pop(stack):
global top
if isempty(stack):
return "Underflow"
else:
popped_item= stack.pop()
if len(stack)==0:
top=None
else:
top=len(stack)-1
return popped_item
def Peek(stack):
global top
if isempty(stack):
return "Underflow"
else:
top=len(stack)-1
return stack[top]
def Display(stack):
global top
if isempty(stack):
return "Underflow"
else:
top=len(stack)-1
print("Top ---> ",stack[top])
for i in range(top-1,-1,-1):
print(stack[i])
##-------------------------__main__---------------------------#
stack=[]
top=None
while True:
print("Stack project: ")
print("1.Push")
print("2.Pop")
print("3.Peek")
print("4.Display")
print("5.Exit")
choice=input("Enter your choice sir/mam!:")
print()
if choice=='1':
item=int(input("Enter your Item sir/mam: "))
Push(stack,item)
elif choice=='2':
item_popped=Pop(stack)
if item_popped == "Underflow":
print("Underflow error!")
print()
else:
print("Comrade just popped: ",item_popped)
print()